my
MessageBox.Show(listbox.Items[0].ToString());
is
"abber"
how can I find listbox item index 0 with "abber"?
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.
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.
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.
With listbox.Items.IndexOf("abber")
That is:
int curIndex = listbox.Items.IndexOf("abber");
if(curIndex >= 0)
{
MessageBox.Show(listbox.Items[curIndex].ToString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With