views:

1672

answers:

2

When I change a value in a DataGridViewComboBoxCell the new value is not immediately applied until that cell leaves focus.

Is there a way to have the new value applied immediately?

+3  A: 

If you handle the EditingControlShowing event on the DataGridView, you can attach an event handler to the underlying ComboBox's SelectedIndexChanged event (or SelectedValueChanged, or any other ComboBox event). It will fire immediately whenever the ComboBox value changes, and you can do whatever you want with the new value.

There's example code for this in the MSDN docs for DataGridViewComboBoxEditingControl.

Andrew Watt
"You can do whatever you want with the new value". What I want to do is tell the combo box to commit the changes to the data bound item. Do you know if there's a command to do this?
Andrew Shepherd
+1  A: 

DataGridView.CommitEdit Method

This might be of some use to you as well. Handle the CurrentCellDirtyStateChanged event, check for Dirty, and Commit the edit. Then you can use the CurrentCell property to access the value that was selected (assuming it was validated).

jomtois