Event when DataGridView row is clicked

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

Hi,

I need an event to fire off when someone clicks anyplace within a
DataGridView row, but whether I use CellContentClick or CellClick, the
event only fires off when clicking on the text within the row and not
anyplace within the row. Is there someway for the event to fire off
regardless of where they click in the row?

Here's a snippet:
Private Sub dgvStuff_CellContentClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgvStuff.CellContentClick
'' blah blah blah my code goes here
End Sub

Thanks --

Alex
 
I don't know if this fits your needs fully but worth trying


Private clickedCell As DataGridViewCell
....
Private Sub GridView_MouseDown(ByVal sender As Object, ByVal e As
MouseEventArgs) Handles GridView.MouseDown
Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X,
e.Y)
If hit.Type = DataGridViewHitTestType.Cell Then
clickedCell =
DataGridView1.Rows(hit.RowIndex).Cells(hit.ColumnIndex)
Dim CurrentCell As DataGridViewCell =
GridView.Item(hit.ColumnIndex, hit.RowIndex)
End If
End Sub
 
Back
Top