I have a DataGridView, within which I have a DataGridViewComboBoxColumn. I’d like to get notification (an event) immediately when the user changes the selection.
Normal DGV behavior is to delay committing edits until after cell exit. This means I don’t get any event until after the user does something (click, keystroke) after the edit – this is one click “too late”.
I have a solution, but it’s messy –
It works, but is there a better way?
Yes, there is a better way.
Use EditingControlShowing (e.Control is the ComboBox).
In the handler simply do:
((ComboBox)e.Control).SelectedIndexChanged -= ...
and ((ComboBox)e.Control).SelectedIndexChanged += ...
Doing always -= and += ensures that there is only one handler attached.
Alternatively, you could create a custom column and override OnSelectedItemChanged in DataGridViewComboBoxEditingControl.
Please login first to submit.