Listbox DisplayMember Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have loaded my listbox with a dataset meaning I did the following.

Me.lstPortfolios.DataSource = Ports.Tables("Ports")
Me.lstPortfolios.DisplayMember = "PortfolioName"
Me.lstPortfolios.ValueMember = "PortfolioID"

And my properties are.
Me.lstPortfolios.MultiColumn = True
Me.lstPortfolios.SelectionMode= System.Windows.Forms.SelectionMode.MultiSimple

I have tried so many ways to get the display value that the user sees, but I
have not found a way yet and I'm getting pissed. It shouldn't be this hard
to find the displayed text where to get the ValueMember is a piece of
cake...enough ranting.

If someone can give me some ides on how to get the displayed text for the
multiple of items may select would be greatly appreciated.
 
Hi,

MasterBlaster said:
I have loaded my listbox with a dataset meaning I did the following.

Me.lstPortfolios.DataSource = Ports.Tables("Ports")
Me.lstPortfolios.DisplayMember = "PortfolioName"
Me.lstPortfolios.ValueMember = "PortfolioID"

And my properties are.
Me.lstPortfolios.MultiColumn = True
Me.lstPortfolios.SelectionMode=
System.Windows.Forms.SelectionMode.MultiSimple

I have tried so many ways to get the display value that the user sees, but
I
have not found a way yet and I'm getting pissed. It shouldn't be this
hard
to find the displayed text where to get the ValueMember is a piece of
cake...enough ranting.

If someone can give me some ides on how to get the displayed text for the
multiple of items may select would be greatly appreciated.

Getting the display-text & value for all selected items:

For Each drv As DataRowView In lstPortfolios.SelectedItems
Dim display As String
display = DirectCast(drv.Item(lstPortfolios.DisplayMember), String)

Dim val As Object
val = drv.Item(lstPortfolios.ValueMember)

Console.WriteLine("{0} {1}", display, val)
Next

HTH,
Greetings
 
Hi MasterBlaster,

Thanks for your post.

I am not sure what does "get the display value that the user sees" mean.
However, if you just wanted to get the user selected values in the listbox,
I think bmermuys has provided the correct way.

If you have any other concern, please feel free to tell us. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top