Constraint violation messagebox of datatable

  • Thread starter Thread starter rakesh
  • Start date Start date
R

rakesh

Hi,

The default behaviour of the datatable when a data
doesn't adhere to a constraint is to pop-up a messagebox
and state the rule. I would like to disable this
behaviour and if possible automate it so as to set the
row errors. Is this possible?

Thanks in advance...
rakesh
 
I did it this way. You only have a overload of the ConstraintException
class.

Create a class which inherit from
"System.Windows.Forms.DataGridTextBoxColumn". You can create your own
TextBox class or use the one in the inherited
System.Windows.Forms.DataGridTextBoxColumn.

Overload the method "protected override bool Commit(CurrencyManager
dataSource, int rowNum)"

Add the following code:

try
{
DataTable.Rows[dataSource.Position][this.MappingName] =
TextBox.Text;
}
catch(ConstraintException)
{
// exception handling code
}

DataTable = source where the data have to be put in
dataSource.Position = DataGrid row
MappingName = Name of this column and the column in the datatable.
They are mapped together.

The messagebox will not popup.

Hope this will help. Good luck
 
Back
Top