Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to fire ComboBox SelectedIndex Changed Event even when old and new index are same?

I have a scenario is which I need to fire the SelectedIndexChanged event of a winform's combox even when the old and new index is same.. I can not use SelectionChangeCommited because the values are being set programmatically .. and it wont get fired. Is it by any chance to force 'SelectedIndexChanged' to fire even when old and same index are same?

like image 514
SamuraiJack Avatar asked Nov 07 '13 06:11

SamuraiJack


People also ask

Which event can be used to detect changes in list ComboBox selection?

ComboBox. SelectedIndexChanged Event (System.

How do you stop a ComboBox SelectedIndexChanged event from firing when the form loads?

You can simply unbind the SelectedIndexChanged event, call your fill function and bind the SelectedIndexChanged event again.

How do I stop a ComboBox from editing?

We can disable the combobox by passing the state as “readonly”.

Is the default event of ComboBox control?

By default, DropDownStyle property of a Combobox is DropDown. In this case user can enter values to combobox. When you change the DropDownStyle property to DropDownList, the Combobox will become read only and user can not enter values to combobox.


2 Answers

It seems wierd that you want the event to refire for the same item. It's probably because you just want to reexecute the event handler logic. Why dont you extract the SelectionChanged logic into a new method and call that one programmatically?

like image 100
atomaras Avatar answered Oct 20 '22 00:10

atomaras


Nothing prevents you from calling event handler directly:

comboBox1_SelectedIndexChanged(comboBox1, new EventArgs()); // or (null, null)

But solution of atomaras is a better (nicer) way to do it.

I myself dislike to use standard components in more-less serious software. Instead I subclass all standard components from very beginning and adding functionality to them as soon as I need it without needs to change anything in the existing forms.

In this case I'd add a public event riser OnSelectedIndexChanged to execute event (to run code inside event handler programmatically).

like image 22
Sinatr Avatar answered Oct 20 '22 00:10

Sinatr