Handling the data error in the DataGridView

0
0

Hi,

Is there a sample for handling the data error in the DataGridView?

I tried it in the following way:

private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
MessageBox.Show(e.Exception.Message, “Fehler bei der Dateneingabe”, MessageBoxButtons.OK, MessageBoxIcon.Information);
e.Cancel = true;
e.ThrowException = false;
}

However, when I tab out of the cell with the data error, I end up in an endless loop.

The message box is displayed again and again. Sometimes several on top of each other. What am I doing wrong?

Thanks

Dirk

  • You must to post comments
0
0

Hi Dirk,
Setting e.Cancel = true requires the user to re-enter the value into the cell. If you want to allow the user to leave the cell, enter e.Cancel = false.
If you’re not sure why the input is firing the DataError event, check the column type.
If you attach a small sample we can look at it in more detail.

I attached a very basic sample of the DGV DataError event.

HTH,
Levie

Attachment
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.