Reputation: 625
I think it is a small problem but I can't find my mistake.
I create a Form called Inventurbeleg which contains a ComboBox called cbProduktBox. With a Controller-Class I create an Object of the Form. Now I want to add Items with the create-Methode.
public static void buttonCreate()
{
inventurbeleg = new Inventurbeleg();
create();
inventurbeleg.Show();
}
My ComboBox gets Items from an array:
public static void create()
{
inventurbeleg.cbProduktBox = new ComboBox();
for (int j = 0; j < Program.arrayMatNr.GetLength(0); j++)
{
String item = Program.arrayMatNr[j, 1];
inventurbeleg.cbProduktBox.Items.Add(item);
}
}
This works correctly, cbProduktBox contains all Items. My Problem is, that the Items arn't shown at my Form. There is an empty comboBox.
Upvotes: 3
Views: 706
Reputation: 4919
You can't do it like that, take a look at this line:
inventurbeleg.cbProduktBox = new ComboBox();
You're creating a new combobox, and when the form loads, the cbProduktBox will initialize again and the changes will be gone
Maybe you can move the create method inside the new form, so when the form loads, call the create method.
Upvotes: 3