• 0

[C#] How to handle combo box events?


Question

Hi

In this C# program I'm writing, I need to be able to determine if the value held in a combo box has changed. So if the current value was "Miss" and then later got changed to "Mrs", I need to be able to recognise the fact that the change in value has occurred.

What code would I need to add to which event handler to make this work?

Thanks for your help

Link to comment
https://www.neowin.net/forum/topic/103641-c-how-to-handle-combo-box-events/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

// in your form's initializer code - should be put their by the designer if you're using VS.NET

this.yourComboBox.SelectedIndexChanged += new System.EventHandler(this.yourComboBox_IndexChanged);

...

private void yourComboBox_IndexChanged(object sender, System.EventArgs e)
{
    // do something because your item changed.
}

It's essentially the same for the TextChangedEvent.

  • 0

click the combo box. on the right, where you can set properties for the object, you can see a little lightning bolt above the properties. click it. this will show you all the possible events that object can trigger. double click on the name of the one you want and it will create it for you, you just have to make the code.

what bangbang suggested is really not a very good idea... (not a personal attack) just use the SelectedIndexChanged action

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.