I am making a WinForms application that includes a form that uses DataGridViewto handle simple data operations. To ensure accurate recording when mitigating interference (read: without use DataGridViewComboBoxColumn), I have several event handlers that temporarily turn DataGridViewTextBoxCellinto an equivalent DataGridViewComboBoxCell, connected to values ββthat are known to be βcleanβ when events are edited, usually when you click on an edited cell ):
private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e)
{
DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
cell.Value = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
UpdateRowStyle(dataGridView.Rows[e.RowIndex]);
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell;
dataGridView.Refresh();
}
and
private void OnCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.DataSource = mDropDownValues[dataGridView.Columns[e.ColumnIndex].Name];
cell.Value = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell;
dataGridView.Refresh();
}
- DataGridViewTextBoxCell, , , , DataGridViewComboBoxCell, , mDropDownValues[]. , , . , dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex] = cell; ( CellBeginEdit, CellEndEdit).
" , SetCurrentCellAddressCore."
, DataGridView? - , ?