Multiselect listbox?

G

Guest

I have a listbox with Selection Mode set to MultiSimple and it's based on a
DataTable.

lstEmp.DataSource = dtEmp.DefaultView
lstEmp.DisplayMember = "EmpName"
lstEmp.ValueMember = "EmpId"

How can I get all of the selected EmpIds and write them to an array of string?

Thanks.
 
D

Daniel Carbajal [MVP]

Very easy , do this :
lbxListBox.SelectionMode = SelectionMode.MultiSimple

and get the values from this array:

lbxListBox.SelectedItems()

Regards,
Daniel Carbajal
Microsoft MVP
 
G

Guest

Hi John

Use the SelectedItems property. Iterate through it - it will be a
DataRowView. Then get Item(0) from it...code like this:

HTH

Nigel Armstrong

Dim s As String
For Each d As DataRowView In Me.ListBox1.SelectedItems
s &= d(0).ToString() & " "
Next
MessageBox.Show(s)
 

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