Click to See Complete Forum and Search --> : [RESOLVED] event for any combobox change?
Crash893
Jul 24th, 2007, 04:41 PM
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?
ComputerJy
Jul 24th, 2007, 05:24 PM
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 followingthis.ControlName.SelectedIndexChanged += new System.EventHandler(this.ComboBoxesSelectedIndexChanged);
Where 'ComboBoxesSelectedIndexChanged' applies to the "EventHandler" delegate
jmcilhinney
Jul 25th, 2007, 12:13 AM
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.
phrajib
Jul 25th, 2007, 05:51 AM
Please clear ur ques. I am not sure what u want to know.
Crash893
Jul 25th, 2007, 12:48 PM
What i would like is to consolidate all this into one event
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);
}
nmadd
Jul 25th, 2007, 02:20 PM
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:
private void Filter(object sender, EventArgs e)
{
MessageBox.Show(
this.comboBox1.Text + " " +
this.comboBox2.Text + " " +
this.comboBox3.Text);
}
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.
Crash893
Jul 25th, 2007, 03:18 PM
works like a charm thanks so much
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.