DataGridView Events Orders (CellParsing & CellValidating)?



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

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
flag = TryParse(e.FormattedValue, ref b);

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question