We help IT Professionals succeed at work.
Get Started

DataGridRow add a row from one DataGRidView to another

Murray Brown
Murray Brown asked
Last Modified: 2012-06-21

I using the following code to add a row from one DataGridView to another
but am having two issues.
Firstly the event doesn't fire and secondly I get an error in the second procedure.

Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick

            Dim oIndex = e.RowIndex
            Call AddRowToDGV2(oIndex)
        Catch ex As Exception

        End Try

    End Sub
    Sub AddRowToDGV2(ByVal intRowIndex As String)
            Dim row As DataGridViewRow = Me.DataGridView1.Rows(intRowIndex)
            'This is where the row from the ist DGV is effectively copied and added to the second DGV
            If row IsNot Nothing Then

                Dim newRow As New DataGridViewRow()


                For i As Integer = 0 To row.Cells.Count - 1
                    newRow.Cells(i).Value = row.Cells(i).Value
                If Me.DataGridView1.Rows(row.Index).DefaultCellStyle.ForeColor <> Color.OrangeRed Then
                    'Don't add the row if it is already owolintshi
                End If

            End If
            '***Color line orange -on the drop
            Me.DataGridView1.Rows(row.Index).DefaultCellStyle.ForeColor = Color.OrangeRed

            MsgBox("There was a problem calling the scenario loading from a drag and drop")
        End Try
    End Sub

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE