DataGridView Events Orders (CellParsing & CellValidating)?

  • Thread starter Thread starter Leon_Amirreza
  • Start date Start date
L

Leon_Amirreza

Its seems very logical that when a user changes a value in a cell first
CellValidating and then CellParsing would get called. But can I cache the
value Parsed in CellValidating (To Actually validate the user's value) in an
object to be used by CellParsing safely?
In other words does this piece of code works or when inside the CellParsing
I should not assume the value of "b" variable is usable (because
DataGridView may have called CellValidating more than once before calling
CellParsing)?


private byte[] b = new byte[1024];
private bool flag;
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
//TryParse is a method I have written to check the value and Parse it if
possible!
flag = TryParse(e.FormattedValue, ref b);
}

private void dataGridView1_CellParsing(object sender,
DataGridViewCellParsingEventArgs e)
{
if (flag)
e.Value = b;
}
 
Back
Top