Hi, can some one please help? I want to double-click on a "customer name" in form1 datagridview and then see "customer details" of selected customer on form2.. (in ms access it called "linked forms") I use VS2012 (vb.net) and SQL database.. Thanks, Michelle

1 Year
Discussion Span
Last Post by Michelle_7

Here's a simple example.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddRow("Frank", "Bowles", "Parker")
        AddRow("Richard", "James", "Harvey")
        AddRow("Kenneth", "Harry", "Morgan")
    End Sub

    Sub AddRow(ByVal col1, ByVal col2, ByVal col3)
        Dim row As Integer = dgvTest.Rows.Add(1)
        dgvTest.Rows(row).Cells(0).Value = col1
        dgvTest.Rows(row).Cells(1).Value = col2
        dgvTest.Rows(row).Cells(2).Value = col3
    End Sub

    Private Sub dgvTest_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTest.CellDoubleClick
        If e.ColumnIndex = 2 Then
            frmDetails.txtFirst.Text = dgvTest.Rows(e.RowIndex).Cells(0).Value
            frmDetails.txtMiddle.Text = dgvTest.Rows(e.RowIndex).Cells(1).Value
            frmDetails.txtLast.Text = dgvTest.Rows(e.RowIndex).Cells(2).Value
        End If
    End Sub

End Class

dgvTest is a DataGridView with three columns. frmDetails is a separate form with three TextBoxes that are populated when the user double clicks on column 2 (last name) of a row in dgvTest. The new form is displayed non-modal so that the user can see details from other rows without closing the details form.


Hello Jim,

Thank you very much for you reply. Can you please say: I want to click on DGV1 and select customer name. Then see "Customer details" (child records) of that selected customer in DGV2 on form2...

Can you please help?



You saw where I loaded the values into the text fields for frmDetails. Retrieve the details from the database and populate the DGV on frmDetails the same way you populate the DGV on the main form.

Edited by Reverend Jim

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.