sample code from intro to vb using .net (dana l.wyatt)
is as follows
*************** *************** **
Private Sub btnShowAll_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnShowAll.Clic k
If lstAnimals.Sele ctedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = lstAnimals.Sele ctedItems.Item( 0)
For index = 1 To lstAnimals.Sele ctedItems.Count - 1
s &= ", " & lstAnimals.Sele ctedItems.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.Da taRowView" instead of the value member I need
*************** *************** ********
my code
If ListBox1.Select edItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = ListBox1.Select edItems.Item(0) .ToString
For index = 1 To ListBox1.Select edItems.Count - 1
Console.WriteLi ne(ListBox1.Sel ectedItems.Item (index).ToStrin g)
Next
MessageBox.Show (s, "Selected Animals")
any assistance would be greatly appreciated
also get invalid cast when try
Dim s As String = ""
For index As Integer = 0 To lstAnimals.Sele ctedItems.Count - 1
Dim drv As DataRowView = CType(lstAnimal s.SelectedItem( index), DataRowView)
s &= drv.Item("name or index of field") & ControlChars.Cr Lf
Next
MessageBox.Show (s, "Selected Animals")
is as follows
*************** *************** **
Private Sub btnShowAll_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnShowAll.Clic k
If lstAnimals.Sele ctedItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = lstAnimals.Sele ctedItems.Item( 0)
For index = 1 To lstAnimals.Sele ctedItems.Count - 1
s &= ", " & lstAnimals.Sele ctedItems.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.Da taRowView" instead of the value member I need
*************** *************** ********
my code
If ListBox1.Select edItems.Count < 1 Then
Exit Sub
End If
Dim s As String
Dim index As Integer
s = ListBox1.Select edItems.Item(0) .ToString
For index = 1 To ListBox1.Select edItems.Count - 1
Console.WriteLi ne(ListBox1.Sel ectedItems.Item (index).ToStrin g)
Next
MessageBox.Show (s, "Selected Animals")
any assistance would be greatly appreciated
also get invalid cast when try
Dim s As String = ""
For index As Integer = 0 To lstAnimals.Sele ctedItems.Count - 1
Dim drv As DataRowView = CType(lstAnimal s.SelectedItem( index), DataRowView)
s &= drv.Item("name or index of field") & ControlChars.Cr Lf
Next
MessageBox.Show (s, "Selected Animals")
Comment