До сих пор мне удавалось обработать событие, когда значение comboBox изменилось, но когда я хочу обновить содержимое другой ячейки этим значением, я получаю 'System.NullReferenceException'.
Это код, который я использую для обработки события (я нашел его в другом вопросе)
void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (this.dataGridBebidas.IsCurrentCellDirty)
{
// This fires the cell value changed handler below
dataGridBebidas.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)dataGridBebidas.Rows[e.RowIndex].Cells[4];
if (cb.Value != null)
{
// Asigno valor de combobox a campo "Alcohol"
dataGridBebidas.Invalidate();
var currentcell = dataGridBebidas.CurrentCellAddress;
var sendingCB = sender as DataGridViewComboBoxEditingControl;
DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dataGridBebidas.Rows[currentcell.Y].Cells[3]; // Cell I want to update
cel.Value = sendingCB.EditingControlFormattedValue.ToString(); // Asign value of the combobox
}
}
Чего мне не хватает?