Click here to Skip to main content
16,013,642 members

Comments by Joaquín Lopez B (Top 1 by date)

Joaquín Lopez B 25-May-15 17:56pm View    
This work for me, when datagridviewcomboboxcell is linked to a bindingsource:

<pre lang="cs">DataGridView dgv = (DataGridView)sender;
if (e.Exception is ArgumentException)
{
object value = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (!((DataGridViewComboBoxColumn)dgv.Columns[e.ColumnIndex]).Items.Contains(value))
{
((DataGridViewComboBoxCell)dgv[e.ColumnIndex, e.RowIndex]).Value = DBNull.Value;
//((DataGridViewComboBoxColumn)dgv.Columns[e.ColumnIndex]).Items.Add(value);
e.ThrowException = false;
}
}
else
{
core.ShowErrorMessage(e.Exception.Message);
e.Cancel = true;
}</pre>