Ответ 1
Вышеприведенный ответ привел меня по дороге первоцвета на некоторое время. Он не работает, поскольку он вызывает несколько событий, и он просто добавляет события. Проблема заключается в том, что вышеперечисленное захватывает DataGridViewEditingControlShowingEvent и не улавливает измененное значение. Поэтому он будет срабатывать каждый раз, когда вы фокусируетесь, а затем покиньте поле со списком, изменилось оно или нет.
Последний ответ о "CurrentCellDirtyStateChanged" - правильный путь. Надеюсь, это поможет кому-то избежать падения кроличьей дыры.
Вот какой код.
// Add the events to listen for
dataGridView1.CellValueChanged +=
new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
dataGridView1.CurrentCellDirtyStateChanged +=
new EventHandler(dataGridView1_CurrentCellDirtyStateChanged);
// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
EventArgs e)
{
if (this.dataGridView1.IsCurrentCellDirty)
{
// This fires the cell value changed handler below
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
// My combobox column is the second one so I hard coded a 1, flavor to taste
DataGridViewComboBoxCell cb = (DataGridViewComboBoxCell)dataGridView1.Rows[e.RowIndex].Cells[1];
if (cb.Value != null)
{
// do stuff
dataGridView1.Invalidate();
}
}