Kevin Davis

Kevin Davis

  • NA
  • 52
  • 51k

Transferring from listview to datagridview

Dec 3 2012 6:42 AM
Hi All,

Trying to add items from listview to datagridview, but keep coming up with this error:
"Specified argument was out of the range of valid values.
Parameter name: rowIndex"

I can add one row with no errors, but when I try to add two or more , this error occurs.

This is my code:

For i As Integer = 0 To form.lvStops.SelectedItems.Count - 1



For Each item As ListViewItem In form.lvStops.SelectedItems
Dim row As New DataGridViewRow
frmAddLoad.Instance.DataGridView1.Rows.Add(row)
With row
.Cells(0).Value = DateTime.Now
.Cells(1).Value = form.lvStops.SelectedItems(i).Text
.Cells(2).Value = form.lvStops.SelectedItems(i).SubItems(1).Text
.Cells(3).Value = form.lvStops.SelectedItems(i).SubItems(2).Text
.Cells(4).Value = form.lvStops.SelectedItems(i).SubItems(3).Text
.Cells(5).Value = form.lvStops.SelectedItems(i).SubItems(4).Text
.Cells(6).Value = form.lvStops.SelectedItems(i).SubItems(5).Text
.Cells(7).Value = form.lvStops.SelectedItems(i).SubItems(6).Text
.Cells(8).Value = form.lvStops.SelectedItems(i).SubItems(7).Text
.Cells(9).Value = form.lvStops.SelectedItems(i).SubItems(8).Text
.Cells(10).Value = form.lvStops.SelectedItems(i).SubItems(9).Text
.Cells(11).Value = form.lvStops.SelectedItems(i).SubItems(10).Text
End With


Next
Next

Any help would be appreciated!

Zcast