Retrieving Multiple selected items from a data bound listbox

  • Thread starter David L Wright II
  • Start date
D

David L Wright II

I have a data bound listbox that I want to select multiple lines then
process each line.
I bound a two column datatable to the listbox and set the DisplayMember
property to the appropriate column of the datatable. I set the
SelectionMode property to MultiExtended.

I am able to load and select multiple lines in the listbox but I can not
figure out how to retrieve both columns for each line selected in the
listbox. I know that there is a SelectedItems collection that contains the
lines selected in the list box but I cannot retrieve both columns for each
item in the SelectedItems collection.

Does anyone know how to accomplish this?

Thanks
 
C

Cor Ligthert

Hi Davix,

What do you mean two columns, the display and the value member?

Than there is as well a property SelectedValue however tell us first if you
mean this?

Cor
 
D

David L Wright II

Cor,

I have already tried the DisplayMember and the SelectedValue properties.
They only contain the information for the first selected item in the list.
I could not retrieve the values for any other selected items in the list.

Thanks,
 
C

Cor Ligthert

Hi David,

A real challenge to find I think it is this

I hope it helps?

Cor
\\\
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim ar(ListBox1.SelectedItems.Count) As String
For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
ar(i) = DirectCast(ListBox1.SelectedItems(i),
DataRowView)(1).ToString
Next
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top