I have a datagridview which is databound to an Entity Framework "table":
public ObjectSet<TEntity> tableData { get; private set; }
private BindingSource tableBinding;
public AuxiliaryTableEditor(ObjectSet<TEntity> something)
{
InitializeComponent();
this.tableData = something;
this.tableBinding = new BindingSource();
this.tableBinding.DataSource = tableData;
this.auxiliaryTableEditorGridView.DataSource = tableBinding;
}
This works perfectly fine.
The problem is this: If a user starts editing / adding a row, if they enter into edit mode in a cell, erase the contents, then tab or click out of it, an unhandled exception will be thrown (as most of the db columns do not allow nulls). This is prefectly normal and acceptable, but I would like to be able to catch and handle these exceptions, and I don't know where / how to catch them.
I have tried using several different event handlers on the datagridview, such as .DataError, .RowValidating, and a few others that I don't remember now... But I can't seem to catch the pesky exceptions.
Any suggestions are greatly appreciated!
EDIT: I should add that the exception is typically something like this: "ConstraintException was unhandled by user code. This property cannot be set to a null value".