nazim corakli
nazim corakli

Reputation: 197

How can I find listbox item index with item value?

my

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

is

"abber"

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

Upvotes: 9

Views: 38882

Answers (2)

user2480047
user2480047

Reputation:

With listbox.Items.IndexOf("abber")

That is:

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

Upvotes: 20

Abin
Abin

Reputation: 2956

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

Upvotes: 5

Related Questions