0

我一直试图找到一种方法来循环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);
}
4

1 回答 1

2

您可以使用while循环:

int index = ListBox.NoMatches;
while ((index = listBox1.FindString(myString, index)) != ListBox.NoMatches)
{
    MessageBox.Show("Found the item \"" + myString + "\" at index: " + index);
}
于 2013-04-24T13:53:26.557 回答