Skip to content

DataGridViewDataErrorContexts

Eyal Lewin

Asked Mar 22, 2010, 4:03 AM EDT1 answer
Share
LinkedInX
C#
 Can anybody explain to me how I handle the DataError Event? I have the
following code but the error does not get picked up by any of them. Looking
at e.Context shows " Parsing | Commit | CurrentCellChange ", how do I get
the individual values?

if (e.Context == DataGridViewDataErrorContexts.Commit)
{
MessageBox.Show("Commit error");
}

if (e.Context == DataGridViewDataErrorContexts.CurrentCellChange)
{
MessageBox.Show("Cell change");
}

if (e.Context == DataGridViewDataErrorContexts.Parsing)
{
MessageBox.Show("parsing error");
}

if (e.Context == DataGridViewDataErrorContexts.LeaveControl)
{
MessageBox.Show("leave control error");
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    DataGridViewDataErrorContexts is an enum and has the FlagsAttribute, which means all members are really bit-oriented flags, so try this:
    Code
    if ((e.Context & DataGridViewDataErrorContexts.Parsing)!=0) {
        MessageBox.Show("parsing error");
    }
    0