my problem is as follows: I have 2 controls created on Form load, button and combobox, I also have event for button, but the event should be able to see the newly created combobox. When I try to call the combo by it's name it says that it don't exist in this context private void Form1_Load(object sender, EventArgs e) { Button przycisk = new Button(); przycisk.Name = "przycisk"; przycisk.Dock = DockStyle.Bottom; przycisk.Text = "Wybierz";
ComboBox kombo = new ComboBox();
kombo.Name = "kombo";
kombo.Dock = DockStyle.Bottom;
kombo.Items.Add("Przycisk");
kombo.Items.Add("Etykeita");
kombo.Items.Add("Pole tekstowe");
Controls.Add(kombo);
Controls.Add(przycisk);
przycisk.Click += new EventHandler(przycisk_Click);
}
private void przycisk_Click(object sender, EventArgs e)
{
kombo.Items.Add("Panel"); //just an example
}
}
Is there a way to make it working ?