Hi guys,

I am new to vb.net i want to know how to pass a datagridview row values onto another form once the row is been double clicked.

Hi

One way to do this would be to use the SelectedRows property of the DataGridView and when it is double clicked you could pass this to your next form. For example, if I had two Forms (Form1 and Form2) and Form1 contained a DataGridView I could set it up so that when the DataGridView is double clicked and one or more rows was selected I could pass these to Form2 via a property.

So, on Form2 you could have the following property:

    Public Property SelectedRows As DataGridViewSelectedRowCollection

This would appear just below the Public Class Form2 line.

Then in Form1, for the DoubleClick event of the DataGridView you could do the following:

    Private Sub DataGridView1_DoubleClick(sender As Object, e As EventArgs) Handles DataGridView1.DoubleClick

        If DataGridView1.SelectedRows.Count > 0 Then

            Dim newForm As New Form2
            newForm.SelectedRows = DataGridView1.SelectedRows
            newForm.Show()

        End If

    End Sub

Then to read from the SelectedRows property on Form2 you could use code similar too:

    MessageBox.Show(SelectedRows(0).Cells(1).Value)

Which will return the value of the first row, second column.

HTH

Comments
Perfect supportings

I have two forms. i already have some values has been displayed in datagrid view in one form including name. In another form, i additionally add some more values including name field. I need to pass the second form values to the datagrid which was in first form by comparing name fields.

This question has already been answered. Start a new discussion instead.