我正在向ListBox
这样的项目添加项目:
myListBox.Items.addRange(myObjectArray);
我还想通过以下方式选择我添加的一些项目:
foreach(MyObject m in otherListOfMyObjects)
{
int index = myListBox.Items.IndexOf(m);
myListBox.SelectedIndices.Add(index);
}
然而index
总是-1
。
有没有不同的方法来获取 a 中对象的索引ListBox
?