Assuming the DataGrig is bound to a datasource, use a CurrencyManager and a DtatRowView:
Dim cm As CurrencyManager
Dim drv As DataRowView
cm = DataGrid1.BindingContext(<data_source_object>)
where <data_source_object> is the DataSource of the DataGrid (e.g., DataTable, DataView, etc.)
Next set up this code to register a click on the grid. I use the MouseUp event, but you could also put this code in the DoubleClick event:
Private Sub DgMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
Dim hit As System.Windows.Forms.DataGrid.HitTestInfo
hit = sender.HitTest(e.X, e.Y)
If hit.Type = Windows.Forms.DataGrid.HitTestType.Cell Or hit.Column = -1 Then
'Dont execute code if clicked on Header row
If hit.Row = -1 Then Exit Sub
'select the entire row (comment out if this is not what you want)
sender.select(hit)
'get selected row into the DataRowView
drv = CType(cm.Current, DataRowView)
End Sub
You can now reference any of the DataGrid's cell contents for the row selected by using the DataRowView's .Item property:
SomeData = drv.Item("SomeFieldName")
or
SomeData = drv.Item(2)
I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson