0
votes

I have a datagridview whihc contains a datagridviewcomboboxcolumn. The data object being bound to the datagrid contains a property whose values are mapped to the datasource values bound to the comboboxcolumn.

My problem is that bad data is occasionally retrieved from the DB, due to which when the datagrid tries to cast the property value to a valid comboboxcolumn value, it throws a data error. I'm unable to catch this in the SET method for the property as well, because it seems on assigning datasource, it doesn't automatically invoke the SET method.

Is there an event I can use to catch this before the data error is thrown? OR any other such workaround that you can think of?

1
Isn't DataBindingComplete called before DataError event triggers? I think you can correct your data there when you assign DataSource. I'm not sure though. - Arie

1 Answers

0
votes

I think the best way would be filter invalid data or correct it, because even if you handle it it means that there will be some inconstancy. Best way is to handle DataError it self where you can fix/silence error (I'm not sure if you meant not to handle that event or to happen before it - AFAIK this is the best place in DataBinding scenario):

private void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
    e.ThrowException = false;
}