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.

2 Years
Discussion Span
Last Post by riyashini111


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

        End If

    End Sub

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


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


Votes + 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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.