im using SelectionChangeCommitted to catch the event when a combobox selected index changed, but I can not get it's new value or index.
private void ruleList_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is ComboBox)
{
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectionChangeCommitted += ruleListColumnComboSelectionChanged;
}
}
private void ruleListColumnComboSelectionChanged(object sender, EventArgs e)
{
string value = ruleList.CurrentCell.Value.ToString(); // just return the old value before the change
}
You can get the new Value using:
Improving on Killercam's method, you can check for the currentcell being a datagridviewcomboboxcell and do (in VB which you can easily convert to C#)
I also added the EndEdit() method for completeness.
Hi try using the
CommitEdit
keyword (CommitEdit
, there is also an example on the MSDN page). Add this to yourDataGridView
:Then you could just listen for the
CellValueChanged
and avoid having to try and register for the ComboBoxValueChanged event on the underlying editing control.If I understand well, you are reacting on the
SelectionChangeCommitted
event from a combobox, but trying to get the value via a grid. Is that correct?My feeling here is that via this
SelectionChangeCommitted
event you can access the value from the combobox directly, but not yet via the grid since it is not commited yet.