0

I'm developing a win forms app, in which there is a DataGridView which has been binded to a DataTable. The DataTable has been applied unique constrain on its EAN field. When a new entry is made with same EAN data, following exception is thrown(As shown in picture).

I want to handle that exception and display some different message and perform some actions, But the problem is I'm Not able to figure out from where is that exception being thrown.

Tried setting break points on various part of the code, where it might occur, also tried wrapping up various part of code into try catch. This exception is not even touching code.(Might be some event issue, I guess!)

 try
 {
    Product_dataGridView.UserAddedRow += Management_dataGridView_UserAddedRow;
    Product_dataGridView.UserDeletedRow += Product_dataGridView_UserDeletedRow;
 }
 catch (Exception exe)
 {
    MessageBox.Show(exe.Message);
 }

Error Image

AbhiAbzs
  • 134
  • 2
  • 12
  • DataGridView System.Data.ConstraintException on row enter [link](https://stackoverflow.com/questions/6587924/datagridview-system-data-constraintexception-on-row-enter) is not my issue. – AbhiAbzs Jun 10 '19 at 17:01

1 Answers1

0

That error message was handled from the following code:-

Added this event in the constructor & then wrote code for handling my problem & changing the error message into more readable message.

public ManagementCtrl()
{
  Product_dataGridView.DataError += Product_dataGridView_DataError;
}

and then,

private void Product_dataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{         
   MessageBox.Show(e.Exception.Message + " Validated");
   //other actions
}
AbhiAbzs
  • 134
  • 2
  • 12