DataGridViewDataErrorContexts problem
-
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"); }
-
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"); }
Hi, DataGridViewDataErrorContexts is an enum and has the FlagsAttribute, which means all members are really bit-oriented flags, so try this:
if ((e.Context & DataGridViewDataErrorContexts.Parsing)!=0) {
MessageBox.Show("parsing error");
}PS: please use PRE tags to show code, as I did (see the difference?) :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.