Robert Hurd

Robert Hurd

  • NA
  • 10
  • 19.7k

How to get a value from the listbox selected item? vb.net 3.5

Feb 12 2011 3:14 PM

Good evening all,
Firstly thank you for the time taken to read this. I'm having some difficulty with a sorted & grouped listbox in WPF vb.net 3.5 that has an items source bound to an ObservableCollection.
What I want to be able to do is to retrieve a piece of data from the ObservableCollection items source depending on what item in the listbox the user has selected.
I've almost got it working but because the listbox is sorted it does not match the index of the items source.
Here is the code that I have so far:
Dim i As Integer = lstBox1.Items.IndexOf(lstBox1.SelectedItem) 
MessageBox
.Show(myListSource.Item(i).Description.ToString, "Source Description") 

As I previously mentioned, because the lstBox is sorted and also grouped the index's don't match up.
Does anyone know how I can get the correct information I want from the List Source depending on the selected item in the list box?
Again, thank you very much for your time,
Rob