您的位置:首页 > 其它

DataGridView绑定DataTable出现大红叉

2016-05-09 14:41 405 查看
听说:因为主线程创建的控件,在子线程中访问就会出现如下问题;

听说:解决方案可以如下几种:

1.在处理操作DataTable的时候,需要将DataTable锁定;

2.使用 delegate 或者 beginIvoke 的方式來解決;

3.调用自带的Invalidate();

4.加上DataError事件并在其中中加上 try catch;

网上查找的解决方案大致就是酱紫;

因为这情况长时间、偶尔会出现,这在测试中。。。。

异常文本:

************** 异常文本 **************

System.NullReferenceException: 未将对象引用设置到对象的实例。

在 System.Windows.Forms.DataGridViewTextBoxCell.PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, Boolean computeContentBounds, Boolean computeErrorIconBounds, Boolean paint)

在 System.Windows.Forms.DataGridViewTextBoxCell.Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, Object value, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)

在 System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)

在 System.Windows.Forms.DataGridViewRow.PaintCells(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)

在 System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)

在 System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)

在 System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)

在 System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)

在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)

在 System.Windows.Forms.Control.WmPaint(Message& m)

在 System.Windows.Forms.Control.WndProc(Message& m)

在 System.Windows.Forms.DataGridView.WndProc(Message& m)

在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** 已加载的程序集 **************

mscorlib

程序集版本: 4.0.0.0

Win32 版本: 4.0.30319.1 (RTMRel.030319-0100)

基本代码: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

----------------------------------------

WCS

程序集版本: 2.0.4575.17354

Win32 版本: 2.0.2.2

基本代码: file:///D:/WCS/WCS.exe

----------------------------------------

System.Windows.Forms

程序集版本: 4.0.0.0

Win32 版本: 4.0.30319.1 built by: RTMRel

基本代码: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: