Just started with Visual Basic Express 2008, after coming from an Access and VBA background.
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.
I have also tried:
***********************
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
***********************
The listbox is a single column bound item with string fields.
What am I missing?
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.
I have also tried:
***********************
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
***********************
The listbox is a single column bound item with string fields.
What am I missing?