How to select listbox item by ValueMember

Если у меня есть два элемента с одним и тем же DisplayMember, но с другим ValueMember, и я хочу выбрать один из двух элементов программно, как мне это сделать?

элементы:

123 -> Peter Pan
234 -> John Doe
345 -> Peter Pan

I не может выбрать последнего Питера Пэна, выполнив

Listbox1.FindStringExact("Peter Pan");

, потому что это возвращает только первое вхождение The following also doesn't work, because it only sets the selected item, but doesn't show it in the list:

Listbox1.SelectedItem = dataTable.Rows.Find(345);

Who can help me with this one?

Update:

Found some more info myself, the list is sorted, therefore when I update the DataTable (which is used to fill the list) the list is resorted, and it seems to select the item that was in place of the edited item.

Listbox1.FindStringExact does only work if the DisplayMember is different

5
задан Michael van der Horst 7 February 2011 в 14:07
поделиться