Getting data from a ListView into an array
- by Joe
I have a ListView control on my form set up like this in details mode:
What I would like to do, is get all the values of the data cells when the user presses the Delete booking button.
So using the above example, my array would be filled with this data:
values(0) = "asd"
values(1) = "BS1"
values(2) = "asd"
values(3) = "21/04/2010"
values(4) = "2"
This is my code so far:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim items As ListView.SelectedListViewItemCollection = _
Me.ManageList.SelectedItems
Dim item As ListViewItem
Dim values(0 To 4) As String
Dim i As Integer = 0
For Each item In items
values(i) = item.SubItems(i).Text
i = i + 1
Next
End Sub
But only values(0) gets filled with the first data cell of the selection (in this case "asd") and the rest of the array entries are blank. I have confirmed this with a breakpoint and checked the array entries myself.
I'm REALLY lost on this, and have been trying for about an hour now. Any help would be appreciated, thanks :)
Also please note that there can only be one row selection at once. Thanks.