Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a DataGridViewComboBoxCell selection change immediately

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?

like image 458
jumpinjackie Avatar asked Apr 11 '09 18:04

jumpinjackie


2 Answers

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.

like image 70
Andrew Watt Avatar answered Sep 22 '22 22:09

Andrew Watt


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).

like image 5
Jon Comtois Avatar answered Sep 21 '22 22:09

Jon Comtois