winform datagridview 显示错误信息
1,当在单元格输入数据时,若数据有误,可以弹出对话框来显示数据错误的原因。
如图:
代码如下:
View Code
1 private void dataGridView1_DataError(object sender,
2 DataGridViewDataErrorEventArgs e)
3 {
4 // If the data source raises an exception when a cell value is
5 // commited, display an error message.
6 if (e.Exception != null &&
7 e.Context == DataGridViewDataErrorContext.Commit)
8 {
9 MessageBox.Show("CustomerID value must be unique.");
10 }
11 }
2 DataGridViewDataErrorEventArgs e)
3 {
4 // If the data source raises an exception when a cell value is
5 // commited, display an error message.
6 if (e.Exception != null &&
7 e.Context == DataGridViewDataErrorContext.Commit)
8 {
9 MessageBox.Show("CustomerID value must be unique.");
10 }
11 }
参考:http://www.cnblogs.com/liulanglang/archive/2007/06/10/778011.html