从绑定到数据网格 Silverlight 的可观察集合中删除项目?
从绑定到 silverlight 数据网格的 observablecollection 中删除行时出现错误。
System.NullReferenceException:未将对象引用设置为 System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 索引)处的 object.at 实例
if (GV.orderItemList.Contains(oOrdritem))
GV.orderItemList.Remove(oOrdritem);
第一次,我删除一条记录,它工作正常,第二次,它给出上述异常
请帮忙
I am getting an error when deleting rows from an observablecollection which is bound to a datagrid in silverlight.
System.NullReferenceException: Object reference not set to an instance of an object.at at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
if (GV.orderItemList.Contains(oOrdritem))
GV.orderItemList.Remove(oOrdritem);
The first time, I delete a record, its working fine, the second time, it gives the above exception
please please please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用RemoveAt而不是Remove,它在某些情况下对我有用。首先,您使用 : 找到项目的索引
,然后尝试删除 :
Try to use RemoveAt instead of Remove, it worked for me in some cases. First you find the index of de item with :
then you try to remove :
进行空检查:(或几个,不确定代码的其余部分是什么样子,所以我强制执行所有内容)
Do a null check: (Or several, not sure what the rest of your code looks like so I'm enforcing everything)
我使用下面的代码对问题进行了排序:
当前聚焦的行仍处于编辑模式,这导致了异常。
I sorted the problem using the code below:
The row which was currently focused was still in edit mode which was causing the exception.