简体   繁体   中英

How can combobox event handler fire after the item drops down?

I am firing a function my_function when the combobox index is selected and it runs depending on the selected combobox selected index.(Using C# code for this in WinForms and WPF)

Here how I declare the event handler:

ComboBox1.SelectionChanged += new SelectionChangedEventHandler(ComboBox1_SelectionChanged);

The event handler of the combobox:

 private void ComboBox1_SelectionChanged(object sender, EventArgs e)
        {
         my_function();
        }

And my_function:

private void my_function(){

if(ComboBox1.SelectedIndex == 0)
//do something

else{
//do something else
}
}

Now my problem is when I click on the combobox, the program starts executing the code before the combobox item drops down. So it looks like the combobox stucks dropping down before it actually drops down after few seconds. Is it possible first the combobox item drops down and then my_function executes?

Using the event SelectionChangeCommitted instance of SelectionChanged will fire your function when committing your select

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM