关于DataGridView_DataError事件的问题
DataGridView中调试时候提示
---------------------------
“DataGridView 默认错误”对话框
---------------------------
DataGridView 中发生以下异常:
System.ArgumentException: 不能将列“CQUESTION_ID”设置为空。请改用 DBNull。
在 System.Data.DataRow.set_Item(DataColumn column, Object value)
在 System.Data.DataRowView.SetColumnValue(DataColumn column, Object value)
在 System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value)
在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex, Object value)
要替换此默认对话框,请处理 DataError 事件。
于是我加入代码
private void classesDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
try...catch ex as System.ArgumentException MsgBox(ex.Message.ToString.Trim, MsgBoxStyle.OkOnly, "系統提示!")...
[解决办法]
我以前一个项目就是这样用得
绑定的数据源是数据类型,输入字符会报错,就这样处理得
你可以调试看一下