使用数组vb.net保存和检索记录

时间:2017-07-24 15:17:13

标签: vb.net

如何从这个数组中检索记录到我的列表视图?

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim countitems As Integer
    countitems = ListView2.Items.Count - 1
    ReDim valueArray(countitems, 5)
    Dim xarray = 0
    For i As Integer = 0 To countitems
        For Each Item As ListViewItem In ListView2.Items
            valueArray(xarray, 0) = Item.Text
            valueArray(xarray, 1) = Item.SubItems(1).Text
            valueArray(xarray, 2) = Item.SubItems(2).Text
            valueArray(xarray, 3) = Item.SubItems(3).Text
            valueArray(xarray, 4) = Item.SubItems(4).Text
            valueArray(xarray, 5) = Item.SubItems(5).Text
            i += 1
        Next
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

如果你想把所有记录放在listview中,你会看到类似的东西。

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim countitems As Integer
    countitems = ListView2.Items.Count - 1
    ReDim valueArray(countitems, 5)
    Dim xarray = 0

    For Each Item As ListViewItem In ListView2.Items
        valueArray(xarray, 0) = Item.Text
        valueArray(xarray, 1) = Item.SubItems(1).Text
        valueArray(xarray, 2) = Item.SubItems(2).Text
        valueArray(xarray, 3) = Item.SubItems(3).Text
        valueArray(xarray, 4) = Item.SubItems(4).Text
        valueArray(xarray, 5) = Item.SubItems(5).Text
        xarray += 1
    Next

End Sub