Event when DataGridView row is clicked


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
 
Ad

Advertisements

K

Kevin S Gallagher

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top