我的代码中有以下逻辑。
Initialize(){
DataGridView view = new DataGridView();
view.BindingSource = bs;
bs.dataSource = dataTable;
//Fill Data Table using Adapter.
da.fill(dataTable);
}
CallMeEveryFewMinutes(DataTable dataTable){
List<String> changed = findChangedOjbects();
// Fill datatable2 with changed objects.
da2.fill(datatable2, changed)
Refresh(dataTable, datatable2);
// dataTable is now refreshed. Bind it again so changes are reflected.
// ********** PROBLEM AREA ***************
// once in a while it throws the below exception.
bs.dataSource = dataTable;
}
不仅如此,它还会为 datagridview.sort(...) 抛出相同的异常 - 偶尔..
任何指针都会非常有帮助。
System.Reflection.TargetInvocationException:调用的目标已引发异常。---> System.ArgumentOutOfRangeException:指定的参数超出了有效值的范围。参数名称: System.Windows.Forms.DataGridView.GetCellAdjustedDisplayRectangle(Int32 columnIndex, Int32 rowIndex, Boolean cutOverflow) 处 System.Windows.Forms.DataGridView.GetCellDisplayRectangle(Int32 columnIndex, Int32 rowIndex, Boolean cutOverflow) 处的 rowIndex .DataGridView.InvalidateCellPrivate(Int32 columnIndex, Int32 rowIndex) 在 System.Windows.Forms.DataGridView.OnCellCommonChange(Int32 columnIndex, Int32 rowIndex) 在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e) 在 System.Windows.Forms .DataGridView。