Clear DataGridView without triggering CellValidating event

0

I'm trying to clean a DataGridView from C #. But when running Rows.Clear() , before that it is executing a CellValidating event that is also appended to the DataGridView

How can I not perform validation before clearing the records?

    
asked by anonymous 27.07.2018 / 16:04

1 answer

0

You can always create a control variable, which is true before doing Rows.Clear() and passes false immediately after:

private bool isClearing = false;

// ...

isClearing = true;
Rows.Clear();
isClearing = false;

// ...

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    if(isClearing)
    {
        // return ou simplesmente e.Cancel = true;
        // dependendo das necessidades
        return;
    }

    // ...
}
    
27.07.2018 / 16:16