Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27156

VS 2010 for loop

$
0
0
Hi guys,
I am writing a for loop where I am transferring one record from one datagridview to another datagridview. I am actually removing the row from the source datagridview and this is causing the problem. please see code below.
Code:

For i = 0 To dgvlistitemtobout.Rows.Count - 1
            noofrows = dgvitemsout.RowCount
            MsgBox(dgvlistitemtobout.Rows(i).Cells(0).Value)
            If dgvlistitemtobout.Rows(i).Cells(0).Value = True Then
                If dgvlistitemtobout.Rows(i).Cells(4).Value = 1 Then
                    dgvitemsout.Rows.Insert(noofrows, New Object() {dgvlistitemtobout.Rows(i).Cells(1).Value, dgvlistitemtobout.Rows(i).Cells(2).Value, dgvlistitemtobout.Rows(i).Cells(3).Value, dgvlistitemtobout.Rows(i).Cells(4).Value})
                    dgvitemsout.Rows(noofrows).HeaderCell.Value = (noofrows + 1).ToString
                    dgvlistitemtobout.Rows.RemoveAt(i)
                End If
            End If
        Next

Removing the row is causing the problem since it is decreasing the number of rows in the source datagridview. please advise.
thanks
Ashley

Viewing all articles
Browse latest Browse all 27156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>