Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dataGridView default error dialog handle

I am trying to hide default datagridview error dialog. I put in the code this event handler:

        this.dataGridView2.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(dataGridView2_DataError);


    private void dataGridView2_DataError(object sender, DataGridViewDataErrorEventArgs e)
    {
        //empty so it doesn't show anything
    }

But still when i try this and leave datagridview cell empty ( delete everything from it), it show me dialog box with error.

Screenshot of error:

enter image description here

like image 393
DoLoop Avatar asked Dec 19 '22 16:12

DoLoop


1 Answers

Try to Handle and Cancel the event:

private void dataGridView2_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
    e.Cancel = true;
}

Also, subscribe to the event in InitializeComponent()

private void InitializeComponent()
{
   //...
   this.dataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.dataGridView2_DataError);
}
like image 134
Shaharyar Avatar answered Jan 02 '23 11:01

Shaharyar