C#backgroundworker中更新datagridview出现滚动条问题

问题具体描述:

在backgroundworder_complete中更新datagridview的数据,出现以下问题:

1、页面不停闪烁;

2、滚动条无法拖动至最下面一条数据,用键盘一行行往下推,到某一行崩溃,出现如下描述的错误

   在 System.Windows.Forms.ScrollBar.set_Value(Int32 value)
   在 System.Windows.Forms.DataGridView.ScrollRows(Int32 rowCount, Int32 deltaY, ScrollEventType scrollEventType)
   在 System.Windows.Forms.DataGridView.ScrollRowsByCount(Int32 rows, ScrollEventType scrollEventType)
   在 System.Windows.Forms.DataGridView.ScrollRowIntoView(Int32 columnIndex, Int32 rowIndex, Boolean committed, Boolean forCurrentCellChange)
   在 System.Windows.Forms.DataGridView.ScrollIntoView(Int32 columnIndex, Int32 rowIndex, Boolean forCurrentCellChange)
   在 System.Windows.Forms.DataGridView.ProcessDownKeyInternal(Keys keyData, Boolean& moved)
   在 System.Windows.Forms.DataGridView.ProcessDownKey(Keys keyData)
   在 System.Windows.Forms.DataGridView.ProcessDataGridViewKey(KeyEventArgs e)
   在 System.Windows.Forms.DataGridView.OnKeyDown(KeyEventArgs e)
   在 System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   在 System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
   在 System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   在 System.Windows.Forms.Control.WmKeyChar(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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   在 System.Windows.Forms.Application.Run(Form mainForm)
   在 SysAnalyse.Program.Main() 位置*******:行号 275“483”的值对于“Value”无效。“Value”应介于 'minimum' 和 'maximum' 之间。参数名: Value


解决:

1、刷新闪烁,可以改为委托刷新;

2、更新完数据之后,加dataGridView1.PerformLayout(),可以解决滚动条问题。

你可能感兴趣的:(C#)