Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi select listbox

Status
Not open for further replies.

JonoB

Programmer
May 29, 2003
147
0
0
GB
Wow, this is driving me crazy.

Just started with Visual Basic Express 2008, after coming from an Access and VBA background.

All I am trying to do is loop through a multi-select listbox and retrieve all the selected items, but it doesnt want to play nice.

What I have tried:

For Each varItem In Me.ListBox1.SelectedItems

MsgBox(Me.ListBox1.Items.Item(varItem))

Next varItem

And I get the error message: Conversion from type 'DataRowView' to type 'Integer' is not valid.

The listbox is a single column bound item with string fields.

What am I missing?
 
I have also tried, with same result

If Me.ListBox1.SelectedItems.Count <> 0 Then
' If so, loop through all checked items and print results.
Dim x As Integer
Dim s As String = ""
For x = 0 To ListBox1.SelectedItems.Count - 1
s = s & "Checked Item " & CStr(x + 1) & " = " & _
CStr(Me.ListBox1.SelectedItems(x)) & ControlChars.CrLf
Next x
MessageBox.Show(s)
End If
 
>Visual Basic Express 2008
You may get better help for this in forum796
 
Hi

Actually you should do this:
Dim iCount as integer
Dim sMsg as string

for icount =0 to listbox1.count-1
if listbox1.selected(icount) then
if smsg<>"" then smsg=smsg & vbcrlf
smsg=smsg & listbox1.list(icount)
end if
next icount
msgbox smsg

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top