all groups > vb.net controls > july 2004 >
You're in the

vb.net controls

group:

Find item in ListBox based on ValueMember


Find item in ListBox based on ValueMember Steve
7/5/2004 5:00:05 PM
vb.net controls:
Hi all

I have a ListBox and I need to find the index of a particular item. I =
know you can find a particular item using: myList.FindString("String To =
Search For"), but the item I'm searching for is in the ValueMember =
property of the ListBox.

I am binding to a DataTable and setting the DataSource, DisplayMember =
and ValueMember, does anyone know how to get the index of the item based =
on the ValueMember?

Kind regards,
Re: Find item in ListBox based on ValueMember GVaught
7/8/2004 12:02:23 PM
nameofListBox.SelectedIndex
nameofListBox.SelectedItem.Text
nameofListBox.Selected.Value

--=20
G Vaught

[quoted text, click to view]
Hi all

I have a ListBox and I need to find the index of a particular item. I =
know you can find a particular item using: myList.FindString("String To =
Search For"), but the item I'm searching for is in the ValueMember =
property of the ListBox.

I am binding to a DataTable and setting the DataSource, DisplayMember =
and ValueMember, does anyone know how to get the index of the item based =
on the ValueMember?

Kind regards,
Re: Find item in ListBox based on ValueMember Steve Amey
7/9/2004 11:18:46 AM
Hiya

The SelectedItem.Text does not work when binding to a DataTable, also, =
the item that is being searched for may not be the selected item. If I =
was to use the selected properties, I would have to loop through all the =
items in the ListBox, selected each one individually then interrogate =
the SelectedValue property.

I have decided to use a different control as it seems that the ListBox =
will not cater for what I want to do without more effort than it's =
worth.

Thanks for your reply.

Kind Regards,
Steve.
[quoted text, click to view]
nameofListBox.SelectedIndex
nameofListBox.SelectedItem.Text
nameofListBox.Selected.Value

--=20
G Vaught

[quoted text, click to view]
Hi all

I have a ListBox and I need to find the index of a particular item. =
I know you can find a particular item using: myList.FindString("String =
To Search For"), but the item I'm searching for is in the ValueMember =
property of the ListBox.

I am binding to a DataTable and setting the DataSource, =
DisplayMember and ValueMember, does anyone know how to get the index of =
the item based on the ValueMember?

Kind regards,
AddThis Social Bookmark Button