将对象添加到 SortedBindingList
我有一个 WinForm,其中包含一个带有组中成员列表的 DataGridView。 该表单包含用于添加新成员和更改当前成员角色的功能(绑定导航器)。 我希望能够对成员进行排序,并通过在组合中引入 SortedBindingList 来实现这一点。 然而,这会产生不幸的结果,使我无法向团队添加新成员。 我得到以下异常:
发生System.InvalidOperationException
Message="无法将项目添加到只读或固定大小列表。"
我理解这个错误,但是有什么办法可以解决这个问题,还是我必须找到其他方法来对列表进行排序?
I have a WinForm containing a DataGridView with a list of members in a group. The form contains functionality (bindingNavigator) for adding new members and changing the role of the current members. I want to be able to sort the members and implemented this by introducing a SortedBindingList to the mix. However this has the unfortunate effect of denying me the ability to add new member to the team. I get the following exception:
System.InvalidOperationException occurred
Message="Item cannot be added to a read-only or fixed-size list."
I understand the error, but is there any way around this or do I have to find some other way to sort the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很幸运地使用了绑定列表视图。 只需将对象保留在通用列表中,然后像这样设置数据源:
将实际对象从列表中取出就像这样简单:
使用 BLV 排序实际上是 比使用 DataView 更快。
I've had a lot of luck using Binding List View. Just keep your objects in Generic lists, and set the DataSource like so:
Getting the actual object back out of the list is as simple as:
Sorting with BLV is actually faster than using a DataView.