1,当在单元格输入数据时,若数据有误,可以弹出对话框来显示数据错误的原因。

如图:

 

winform datagridview 显示错误信息

 

代码如下:

 

 

 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         }

相关文章: