newbieneedshelp

I would like when the user double clicks the datagridview that "label2.text" equals the data in the "ID" column of that record. The code in red is where I have various attempts at doing this with no luck.




Private Sub WagerAccessDataGridView_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles WagerAccessDataGridView.CellDoubleClick

Label2.Text = WagerAccessDataGridView.CurrentRow.Cells
Form2.Location = New Point(Me.Location.X + 220, Me.Location.Y + 100)
Form2.ShowDialog()
End Sub

Thanks once again


Re: Windows Forms Data Controls and Databinding double click datagrid view and get data?

Zhi-Xin Ye - MSFT

Label2.Text = WagerAccessDataGridView.CurrentRow.Cells["id"].Value.toString().




Re: Windows Forms Data Controls and Databinding double click datagrid view and get data?

newbieneedshelp

When I tried your code I keep getting the error "column ID can not be found". I tried other columns in my database and got the same error. Also to get to code to work I haad to replace the brackets with parenthesis. Code in red is what I changed from yours.

Label2.Text = WagerAccessDataGridView.CurrentRow.Cells("ID").Value.ToString()




Re: Windows Forms Data Controls and Databinding double click datagrid view and get data?

Zhi-Xin Ye - MSFT

For C#,we use brackets .Cells["ID"], for VB.NET, we use parenthesis .Cells("ID")