How can I find listbox item index with item value?

2019-02-17 12:46发布

问题:

my

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

is

"abber"

how can I find listbox item index 0 with "abber"?

回答1:

With listbox.Items.IndexOf("abber")

That is:

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


回答2:

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