报错信息:
---------------------------
“DataGridView 默认错误”对话框
---------------------------
DataGridView 中发生以下异常:
System.IndexOutOfRangeException: 索引 0 没有值。
在 System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 rowIndex)
要替换此默认对话框,请处理 DataError 事件。
---------------------------
确定
---------------------------
可能原因:
虽然在winform程序中允许非UI线程访问控件,如下代码:
Control.CheckForIllegalCrossThreadCalls = false;//允许非UI线程访问控件
但是仍然在非ui线程*问DataGridView,并且逻辑类似于
https://www.it610.com/article/1454101.htm
或
http://www.it1352.com/606779.html
所提到的
这种情况下,就会出现上述报错。
解决方法:使用Control.Invoke,用ui线程去访问DataGridView。