I am developing project in widows c#.net. In the form i have more than 8 combobox control. I will load data to combobox2 when combobox1 selection is changed like below.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.DataSource = DataTable;
comboBox2.DisplayMember="Name";
comboBox2.ValueMember = "ID";
}
Combobox3 will be loaded when i select combobox2 like below.
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox3.DataSource = DataTable;
comboBox3.DisplayMember = "Age";
comboBox3.ValueMember = "AgeCode";
}
Like i will load data to the rest of combobox.
The problem here is error will occur, if i did not check in comboBox1_SelectedIndexChanged
method whether comboBox2 is loaded or not.
I know we can check this by using Boolean variable, but horrible thing is we need to maintain its "true/false" state for rest all methods.
so what I have thought to fix this in simple way is that, I will use Add(combobox, Methodname)
method and Remove(combobox, method)
methods to add and remove the comboBox_SelectedIndexChanged
function from combobox SelectedIndexChanged
event.
But I couldn't pass the method as parameter. Can anybody tell me that how to pass method as parameter for my requirement.