我很难找到一种方法来循环listbox.FindString()
每个项目来搜索项目列表框。举个例子:
示例代码:
string myString = "hi";
int index = listBox1.FindString(myString, -1);
if (index != -1) {
listBox1.SetSelected(index, true);
MessageBox.Show("Found the item \"" + myString + "\" at index: " + index);
}
答案 0 :(得分:2)
您可以使用while
循环:
int index = ListBox.NoMatches;
while ((index = listBox1.FindString(myString, index)) != ListBox.NoMatches)
{
MessageBox.Show("Found the item \"" + myString + "\" at index: " + index);
}