Search code examples
variablesdatagridviewvb.net-2010double-clickselectedvalue

how to get value in a variable on datagridview selected row doubleclick event


I have this datagrid view:

enter image description here

Now when the first row is double clicked i want its all data to be saved in variables, like the field name should come in a variablename name aand First Name should come in another variaablename fname and so on.

I have been trying to get the values using DataGridView1.CellContentDoubleClick event, with the property called SelectedCells but the intellisense is not providing me any information on how i can get the value of each column in that particular selected row.


Solution

  • Finally i got the answer working for me so sharing it here:

    Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
            frm_dashboard.lbl_pnum_text.Text = DataGridView1.SelectedRows(0).Cells(0).Value
            frm_dashboard.lbl_pname_text.Text = DataGridView1.SelectedRows(0).Cells(2).Value + " " + DataGridView1.SelectedRows(0).Cells(1).Value
            frm_dashboard.lbl_paddress_text.Text = DataGridView1.SelectedRows(0).Cells(4).Value
            frm_dashboard.Enabled = True
            Me.Hide()
        End Sub