Hello, my code is not transferring the selected row data into the targeted text boxes on the other form when i click or select the row, i need help here , that the code

Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick

    If Me.DataGridView2.CurrentRow.Selected = True Then

        With Form20

            .txtSup_Name.Text = ""
            .txtSup_Phone.Text = ""
            .txtSup_Address.Text = ""

        End With

        Dim i As Integer

        i = DataGridView2.CurrentRow.Index

        With Form20

            .txtSup_Name.Text = DataGridView2.Item(1, i).Value
            .txtSup_Phone.Text = DataGridView2.Item(2, i).Value
            .txtSup_Address.Text = DataGridView2.Item(3, i).Value

        End With


    End If

    Me.Close()
   Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

        If e.RowIndex < 0 Then Exit Sub

        Dim dgv As DataGridView = sender
        TextBox1.Clear()

        For i As Integer = 0 To dgv.ColumnCount - 1
            TextBox1.AppendText(dgv.Rows(e.RowIndex).Cells(i).Value & vbCrLf)
        Next

    End Sub

The above code will copy all cells in the selected row into TextBox1.Text. The initial test is to prevent an error if one of the column headers is clicked.

e.RowIndex is the zero-relative index of the clicked row. Correspondingly, e.ColumnIndex is the same but for the column.

Am going to try this code but i already have the feeling it an intelligent piece of code, thanks alot Reverend Jim

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.