From dePoPo.net

How to determine which row has been clicked on a datagridview

Posted in: Forms and Grids
By dePoPo
Mar 6, 2009 - 11:50:47 AM

This code determines the id of the record dat has been clicked in a datagridview.
Place the following code into the CellContentClicked event of the datagridview



Dim n_current_row As Integer
Dim n_current_column As Integer
Dim n_clicked_id As Integer
Dim d_row As DataGridViewRow
 
n_current_row = e.RowIndex
n_current_column = e.ColumnIndex
If n_current_row < 0 Then Exit Sub ' no data
d_row = DataGridView1.Rows(n_current_row) ' d_row is now a row object with all fields
n_clicked_id = d_row.Cells(0).Value ' asuming field(0) contains the id


© Copyright 2010 by dePoPo.net