日期:2014-05-19  浏览次数:21191 次

怎么解决DataGridView控件的绘制错误啊?高手们。来帮帮忙
当我的程序频繁的在内存中的DataTable绑定到DataGridView上的时候,就会出现绘制的异常错误,但就是必须每时每刻都要把那个DATATABLE显示出来,请问高手们怎么解决啊?
使用的绑定方法是dataGridView1.DataSource   =   CacheDataTable;
大约300毫秒就绑定一次的!
不能绑定慢点的,因为要及时的显示最新!

出现以下错误:
See   the   end   of   this   message   for   details   on   invoking  
just-in-time   (JIT)   debugging   instead   of   this   dialog   box.

**************   Exception   Text   **************
System.NullReferenceException:   Object   reference   not   set   to   an   instance   of   an   object.
      at   System.Data.DataView.GetRecord(Int32   recordIndex)
      at   System.Data.DataView.GetRow(Int32   index)
      at   System.Data.DataRowView.get_Row()
      at   System.Data.DataRowView.System.ComponentModel.IDataErrorInfo.get_Error()
      at   System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32   rowIndex)
      at   System.Windows.Forms.DataGridViewRow.GetErrorText(Int32   rowIndex)
      at   System.Windows.Forms.DataGridViewRow.Paint(Graphics   graphics,   Rectangle   clipBounds,   Rectangle   rowBounds,   Int32   rowIndex,   DataGridViewElementStates   rowState,   Boolean   isFirstDisplayedRow,   Boolean   isLastVisibleRow)
      at   System.Windows.Forms.DataGridView.PaintRows(Graphics   g,   Rectangle   boundingRect,   Rectangle   clipRect,   Boolean   singleHorizontalBorderAdded)
      at   System.Windows.Forms.DataGridView.PaintGrid(Graphics   g,   Rectangle   gridBounds,   Rectangle   clipRect,   Boolean   singleVerticalBorderAdded,   Boolean   singleHorizontalBorderAdded)
      at   System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs   e)
      at   System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs   e,   Int16   layer,   Boolean   disposeEventArgs)
      at   System.Windows.Forms.Control.WmPaint(Message&   m)
      at   System.Windows.Forms.Control.WndProc(Message&   m)
      at   System.Windows.Forms.DataGridView.WndProc(Message&   m)
      at   System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&   m)
      at   System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&   m)
      at   System.Windows.Forms.NativeWindow.Callback(IntPtr   hWnd,   Int32   msg,   IntPtr   wparam,   IntPtr   lparam)



------解决方案--------------------
up
------解决方案--------------------
使用的绑定方法是dataGridView1.DataSource = CacheDataTable;
大约300毫秒就绑定一次的!
不能绑定慢点的,因为要及时的显示最新!

这个错误 是你绑定的对象为NULL 估计是太快了 对象数据还没生成. 为什么这么频繁绑定> ?总有理由吧,. 建议你读取 新的数据部分, 然后以添加的方式放到DS的TABLE中在绑定性能会好很多
------解决方案--------------------
你贴部分代码上来看看
------解决方案--------------------
DATATABLEVIEW难道他一直没释放? 都是同一个对象? 自动更新是什么意思?

绑定一次上去以后,DATATABLEVIEW就会自动的更新显示数据,有更新时自动重新显示新的数据的了。。上面那种方法已经没有用的了。。只要绑定一次就行。。但是还是出现那个问题