删除System.ArgumentOutOfRangeException时DataGridView绑定BindingList错误:提供的行索引超出范围。 [英] DataGridView binding BindingList error when deleting System.ArgumentOutOfRangeException: Row index provided is out of range.

查看:147
本文介绍了删除System.ArgumentOutOfRangeException时DataGridView绑定BindingList错误:提供的行索引超出范围。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个奇怪的问题,两个DataGridView绑定到同一个BindingList。两个DataGridViews都没有显示,它们位于TabControl的不同选项卡中。因此,如果我启动软件并查看第一个dataGridView并从我的绑定
列表中删除一个项目,它应该反映在两个dataGridViews中。奇怪的是,如果我移动到选项卡2然后返回选项卡1(因此datagridView2有机会至少绘制一次)我从绑定列表中删除项目时不会出现此异常。如果从未显示
datagridview2并且我从绑定列表中删除了我的项目,则会出现此错误:

I have a strange issue with two DataGridView binded to the same BindingList. The two DataGridViews are not both shown, they are in different tabs in a TabControl. So if I start the software and see the first dataGridView and delete an item from my binding list it should be reflected in both dataGridViews. The strange this is that if I move to tab 2 and then back to tab 1 ( so datagridView2 has the chance to paint itself at least once) I don't get this exception when I delete an item from my bindinglist. If datagridview2 is never shown and I delete my item from binding list I get this error:

************** Exception Text **************
System.ArgumentOutOfRangeException: Row index provided is out of range.
Parameter name: rowIndex
   at System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)
   at System.Windows.Forms.DataGridView.OnRowGlobalAutoSize(Int32 rowIndex)
   at System.Windows.Forms.DataGridView.OnRemovedRow_PostNotification(DataGridViewRow dataGridViewRow, Point newCurrentCell)
   at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
   at System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
   at System.Windows.Forms.DataGridViewRowCollection.RemoveAtInternal(Int32 index, Boolean force)
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
   at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs e)
   at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType type, Int32 index)
   at System.ComponentModel.BindingList`1.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)
   at XXXX.MainForm.buttonDownloadDelete_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(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)

看起来像一个.NET错误,如果一个datagridview没有改变,至少刷一次它自己不会识别行数。奇怪的是,当抛出异常时,我已经跟踪了datagridview2中的行数,并且
是正确的,它包含所有行。为什么抛出这个例外?有没有解决方法? (除了为每个datagridview都有一个绑定列表)。

Seems like a .NET bug, if one datagridview doesn't have the change to paint itself at least once it will not recognize the number of rows. The weird thing is that I've traced the number of rows in my datagridview2 right when the exception is thrown and it is correct, it contains all the rows. Why is it throwing that exception ? Is there any workarounds ? (besides having a bindinglist for each datagridview).

谢谢,

Daniel

-Creator -

-Creator-

推荐答案

你能发布你的码?我不认为是一个.NET错误。
Can you post your code? i don't think is a .NET bug.


这篇关于删除System.ArgumentOutOfRangeException时DataGridView绑定BindingList错误:提供的行索引超出范围。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆