Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"?

like image 657
nazim corakli Avatar asked Jul 12 '13 09:07

nazim corakli


People also ask

How do I get ListBox index?

To retrieve a collection containing the indexes of all selected items in a multiple-selection ListBox, use the SelectedIndices property. If you want to obtain the item that is currently selected in the ListBox, use the SelectedItem property.

How do you get the selected items and search the ListBox items?

To retrieve a collection containing all selected items in a multiple-selection ListBox, use the SelectedItems property. If you want to obtain the index position of the currently selected item in the ListBox, use the SelectedIndex property.

Which function is used to fetch a value based on the number returned by a ListBox control?

ListBox control has a GetItemText which helps you to get the item text regardless of the type of object you added as item. It really needs such GetItemValue method. Using above method you don't need to worry about settings of ListBox and it will return expected Value for an item.


1 Answers

With listbox.Items.IndexOf("abber")

That is:

int curIndex = listbox.Items.IndexOf("abber");
if(curIndex >= 0)
{
    MessageBox.Show(listbox.Items[curIndex].ToString());
}
like image 176
varocarbas Avatar answered Oct 23 '22 18:10

varocarbas