windows form programming
-
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 -
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 form1Your 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.
-
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 form1It 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;
}
...
}