CheckedListBox.RemoveAt(lastItemIndex) 导致列表中的显示问题
我有一个绑定到自定义类型的通用列表的选中列表框。当我删除列表中的其他项目时,显示正常,但是当我删除列表中的最后一个项目时,列表将显示类型名称而不是显示名称。
_selResolutions.RemoveAt(selIndex);
cklResolutions.DataSource = null;
cklResolutions.BeginUpdate();
cklResolutions.DataSource = _selResolutions;
cklResolutions.DisplayMember = "LongDesc";
cklResolutions.ValueMember = "LongDesc";
cklResolutions.EndUpdate();
for (var i = 0; i < _selResolutions.Count; i++)
{
cklResolutions.SetItemChecked(i, _selResolutions[i].Selected);
}
当使用上面的代码删除最后一个项目时,显示看起来像这样。
[ ] Resolution
[ ] Resolution
[ ] Resolution
[ ] Resolution
[ ] Resolution
为什么会发生这种情况?我在这里错过了什么吗?我该如何纠正这个问题?
I have a checkedlistbox that's bound to a generic list of custom type. When I remove other items on the list, the display is okay, but when I remove the last item on the list, the list shows up w/ the type name instead of the displayname.
_selResolutions.RemoveAt(selIndex);
cklResolutions.DataSource = null;
cklResolutions.BeginUpdate();
cklResolutions.DataSource = _selResolutions;
cklResolutions.DisplayMember = "LongDesc";
cklResolutions.ValueMember = "LongDesc";
cklResolutions.EndUpdate();
for (var i = 0; i < _selResolutions.Count; i++)
{
cklResolutions.SetItemChecked(i, _selResolutions[i].Selected);
}
the display looks like this when the last item is removed w/ the above code.
[ ] Resolution
[ ] Resolution
[ ] Resolution
[ ] Resolution
[ ] Resolution
why is this happening? am i missing something here? how do i correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试改用 BindingSource。这为数据源提供了一个可以通知 DGV 更改的视图:
Try using a BindingSource instead. This provides the DataSource a view that can inform the DGV of changes: