Results 1 to 7 of 7

Thread: [RESOLVED] event for any combobox change?

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Resolved [RESOLVED] event for any combobox change?

    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?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: event for any combobox change?

    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 following
    Code:
    this.ControlName.SelectedIndexChanged += new System.EventHandler(this.ComboBoxesSelectedIndexChanged);
    Where 'ComboBoxesSelectedIndexChanged' applies to the "EventHandler" delegate
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: event for any combobox change?

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Lively Member
    Join Date
    Mar 2005
    Location
    Dhaka, Bangladesh
    Posts
    102

    Re: event for any combobox change?

    Please clear ur ques. I am not sure what u want to know.
    Please Rate every reply if it is useful to u

  5. #5

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: event for any combobox change?

    What i would like is to consolidate all this into one event



    c# Code:
    1. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    2.         {
    3.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    4.         }
    5.         private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
    6.         {
    7.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    8.         }
    9.         private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
    10.         {
    11.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    12.         }
    13.         private void comboBox1_TextUpdate(object sender, EventArgs e)
    14.         {
    15.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    16.         }
    17.         private void comboBox2_TextUpdate(object sender, EventArgs e)
    18.         {
    19.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    20.         }
    21.         private void comboBox3_TextUpdate(object sender, EventArgs e)
    22.         {
    23.             Filter(comboBox1.Text, comboBox2.Text, comboBox3.Text);
    24.         }
    25.         private void Filter(string date, string ref_num, string rootcause)
    26.         {
    27.             MessageBox.Show(date + " " + ref_num + " " + rootcause);
    28.         }

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: event for any combobox change?

    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:
    Code:
            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.

  7. #7

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: event for any combobox change?

    works like a charm thanks so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width