sample code from intro to vb using .net (dana l.wyatt)
is as follows
********************************
Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowAll.Click
If lstAnimals.SelectedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = lstAnimals.SelectedItems.Item(0)
For index = 1 To lstAnimals.SelectedItems.Count - 1
s &= ", " & lstAnimals.SelectedItems.Item(index)
Next
MessageBox.Show(s, "Selected Animals")
End Sub
***************************
and it works
but in my program it doesnt
I have to add .ToString to avoid
Cast from type 'DataRowView' to type 'String' is not valid.
but then it prints "System.Data.DataRowView" instead of the value member I need
**************************************
my code
If ListBox1.SelectedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = ListBox1.SelectedItems.Item(0).ToString
For index = 1 To ListBox1.SelectedItems.Count - 1
Console.WriteLine(ListBox1.SelectedItems.Item(index).ToString)
Next
MessageBox.Show(s, "Selected Animals")
any assistance would be greatly appreciated
is as follows
********************************
Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowAll.Click
If lstAnimals.SelectedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = lstAnimals.SelectedItems.Item(0)
For index = 1 To lstAnimals.SelectedItems.Count - 1
s &= ", " & lstAnimals.SelectedItems.Item(index)
Next
MessageBox.Show(s, "Selected Animals")
End Sub
***************************
and it works
but in my program it doesnt
I have to add .ToString to avoid
Cast from type 'DataRowView' to type 'String' is not valid.
but then it prints "System.Data.DataRowView" instead of the value member I need
**************************************
my code
If ListBox1.SelectedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = ListBox1.SelectedItems.Item(0).ToString
For index = 1 To ListBox1.SelectedItems.Count - 1
Console.WriteLine(ListBox1.SelectedItems.Item(index).ToString)
Next
MessageBox.Show(s, "Selected Animals")
any assistance would be greatly appreciated