如何通过项目值查找列表框项目索引?

9

my

MessageBox.Show(listbox.Items[0].ToString());

"abber"

如何使用“abber”查找列表框中索引为0的项目?

请明确您的需求。 - Rajeev Kumar
2个回答

19

使用listbox.Items.IndexOf("abber")

即:

int curIndex = listbox.Items.IndexOf("abber");
if(curIndex >= 0)
{
    MessageBox.Show(listbox.Items[curIndex].ToString());
}

5
 int index = listBox1.Items.IndexOf("Specify string here");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接