LRAC - 1 year ago 65

Vb.net Question

I have a ListView with 4 columns and close to 1500 rows. I want to know how to pass it to an array. I'd like the rows and columns in the ListView to match the dimensions in the array.

`Dim ListView1 As ListView`

ListView1 = New ListView()

Answer Source

Given the data is already in the `ListView`

you could do something like this:

```
Dim matrix(ListView1.Items.Count - 1, 3)
For r As Integer = 0 To ListView1.Items.Count - 1
Dim itemX = ListView1.Items(r)
matrix(r, 0) = itemX.Text
matrix(r, 1) = itemX.SubItems(0).Text
matrix(r, 2) = itemX.SubItems(1).Text
matrix(r, 3) = itemX.SubItems(2).Text
Next
```

So this is how you do it by dynamically reference columns - `Subitem`

s:

```
Dim matrix(ListView1.Items.Count - 1, 3)
For r As Integer = 0 To ListView1.Items.Count - 1
Dim itemX = ListView1.Items(r)
matrix(r, 0) = itemX.Text ' The first item in the array
For c As integer = 1 To itemX.Subitems.Count
matrix(r, c) = itemX.Subitem(c - 1).Text
Next
Next
```