Could some one point me in the direction of how to have multi combo boxes or other controls all fire off the same change event?
Printable View
Could some one point me in the direction of how to have multi combo boxes or other controls all fire off the same change event?
You can do that in 2 ways
1- Select the controls you want by holding the "Ctrl" key and clicking on them, then go to the Properties window, switch to the "Events" tab and double click on the event you want.
2- You can go to the Windows Designer generated code, and add to each control the followingWhere 'ComboBoxesSelectedIndexChanged' applies to the "EventHandler" delegateCode:this.ControlName.SelectedIndexChanged += new System.EventHandler(this.ComboBoxesSelectedIndexChanged);
Once a method exists you can also select it from the drop-down list for a control in the Properties window. That's important if you create the event handler for multiple controls and then add another control later on.
Please clear ur ques. I am not sure what u want to know.
What i would like is to consolidate all this into one event
c# Code:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void comboBox1_TextUpdate(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void comboBox2_TextUpdate(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void comboBox3_TextUpdate(object sender, EventArgs e) { Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text); } private void Filter(string date, string ref_num, string rootcause) { MessageBox.Show(date + " " + ref_num + " " + rootcause); }
You don't need to pass the ComboBoxes to your method every time if they are always going to be the same ComboBoxes. Your method can look like this:
Then you can, as jmcilhinney suggested, select all your ComboBoxes in design view, open the Properties window and then select your Filter method from the dropdown next to your required events.Code:private void Filter(object sender, EventArgs e)
{
MessageBox.Show(
this.comboBox1.Text + " " +
this.comboBox2.Text + " " +
this.comboBox3.Text);
}
works like a charm thanks so much