1

我有一个绑定列表,在某些难以重现的条件下,当向其中添加值时会引发以下异常:

System.ArgumentException:复杂 DataBinding 接受 IList 或 IListSource 作为数据源。在 System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
在 System.Windows.Forms.Binding.SetPropValue(Object value)
在 System.Windows.Forms.Binding.PushData(Boolean force)
在 System.Windows.Forms。 System.Windows.Forms.CurrencyManager.CurrencyManager_PushData() 上 System.Windows.Forms.CurrencyManager.OnItemChanged(ItemChangedEventArgs e)上 System.Windows.Forms.BindingManagerBase.PushData
( ) 上的BindingManagerBase.PushData(Boolean&success) 。 Forms.CurrencyManager.List_ListChanged(对象发送者,ListChangedEventArgs e)



在 System.ComponentModel.ListChangedEventHandler.Invoke(Object sender, ListChangedEventArgs e)
在 System.ComponentModel.BindingList 1.InsertItem(Int32 index, T item) 在 System.Collections.ObjectModel.Collection`1.Add(T item) ...1.OnListChanged(ListChangedEventArgs e)
at System.ComponentModel.BindingList


我可以理解它是在创建列表时发生的,还是在更改其中一个属性时发生的,但这只发生在向它添加某些值时。它声明如下:

private BindingList<IBusinessObject> _bindingList = new BindingList<IBusinessObject>();

然后像这样稍后使用(这是抛出异常的地方):

_bindingList.Add(myBusinessObject);

更糟糕的是,这发生在以前工作的生产代码中,这里涉及的代码最近都没有被编辑过。我怀疑这是某种微妙的数据交互问题,这也是它很少发生的原因,但坦率地说,我很茫然,因为异常的起源点在 .Net 内部深处。

更新:它实际上不是单个表单,而是用于支持多个表单/对话框的对象模型的一部分。这是非常复杂的代码,而不是我编写的代码,只是在维护/增强。深入研究代码后,似乎 BindingList 被添加到更多域对象中,并最终用于使用对象的字符串属性填充 ImageListBox。有问题的字符串不应为空或空白,但由于代码所在的位置以及难以重现附加调试器验证的错误将是有问题的。空值是否会导致 BindingList 在问题实际所在位置如此遥远的位置引发异常?在最终将其作为数据源分配给相关的 ImageListBox 列表之前,该对象实际上被插入到 3 个或 4 个其他对象/集合中(即使这样,它也取决于其他几个选择,以确定最终是哪个 BindingList 对象用于填充列表)。

4

1 回答 1

1

看起来您将某种列表控件的 DataSource 属性绑定到 IBusinessObject 的属性,并且该属性返回的值作为 DataSource 无效。您能否更具体地了解您在此表单上使用的所有绑定?

于 2009-05-21T18:30:22.647 回答