当与列表框中的一个项目交互时,它很简单:
myClass citem = (myClass)myListBop.SelectedItem.
viewModel.doSomethingWithItem(cItem)
多项目的正确方法是什么?我已经看到了简单地将数据复制到List的示例,但是最好避免复制并进行正确的转换? Resharper告诉我,我可能做错了什么:
建议如下:
Suspicious case: there is no type in the solution which is inherited from both "Sytem.Windows.Forms.ListBox.SelectedObjectCollection" and "System,Collections.Generic.IList<myClass>"
基本上IList / SelectedObjectCollection的用途是什么?
答案 0 :(得分:1)
多项目的正确方法是什么?
SelectedObjectCollection
未实施IList<T>
。你不能只是施展它。相反,您可以使用Cast
方法将所有项目转换为您的类型并将它们放入列表中:
myListBop.SelectedItems.Cast<myClass>().ToList();