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?
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?
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;
}
// ...
}