Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. windows form programming

windows form programming

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathan Revka
    wrote on last edited by
    #1

    I am trying to access a listbox in a class that is not Form1.cs but I am having difficulty. How do I access this list box? I have tried:

    public class DeckManagement: Form

    and

    public class DeckManagement: WarGame
    //WarGame is the name of the class inside form1

    V M 2 Replies Last reply
    0
    • N Nathan Revka

      I am trying to access a listbox in a class that is not Form1.cs but I am having difficulty. How do I access this list box? I have tried:

      public class DeckManagement: Form

      and

      public class DeckManagement: WarGame
      //WarGame is the name of the class inside form1

      V Offline
      V Offline
      Vikram A Punathambekar
      wrote on last edited by
      #2

      Your code seems totally irrelevant to the problem at hand. :confused:

      Nathan Revka wrote:

      but I am having difficulty

      Does it not compile, or do you get a runtime error? I would guess you need to make WarGame a public inner class of Form1, but that is terrible design - you should have WarGame as a full class in its own right, in WarGame.cs.

      Cheers, Vikram. (Proud to have finally cracked a CCC!)

      Recent activities: TV series: Friends, season 10 Books: Fooled by Randomness, by Nassim Nicholas Taleb.


      Carpe Diem.

      1 Reply Last reply
      0
      • N Nathan Revka

        I am trying to access a listbox in a class that is not Form1.cs but I am having difficulty. How do I access this list box? I have tried:

        public class DeckManagement: Form

        and

        public class DeckManagement: WarGame
        //WarGame is the name of the class inside form1

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        It is probably a better idea to expose a public method or property in your Form1 class that you would execute from your satellite class. For example, if you needed to access the listbox from a different class so you can retrieve the selected index, you might within your Form1 class expose a public method:

        public partial class Form1
        {
        ...
        public int GetListSelectedIndex()
        {
        return listBox1.SelectedIndex;
        }
        ...
        }

        MishaInTheCloud.blogspot.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups