DATAGRIDVIEW - detect Header click

T

teo

hallo

In a DataGridView
how/where may I detect
the click on the header of a column
versus
the click on a cell "inside" the grid ?

I tried
by using the
DataGridView1_CellMouseClick event (and other)
and
by adopting the
CurrentCellAddress and CurrentRow.Index ways

but what I got was ALWAYS the index of the current blue selected cell
(I'd have expected a '0' value instead, or something that said to me
it was the click on the header row and not on a "good" rorw)

Here what I tried:

1)
'get cell indexes
Dim myCurrentCell As Drawing.Point =
DataGridView1.CurrentCellAddress
'get clicked row index
Dim myClickedRow As Integer = myCurrentCell.Y
'DataGridView1.CurrentRow.Index

2)
'get clicked row index
Dim myClickedRow As Integer =DataGridView1.CurrentRow.Index
 
A

Ahmed

You have to choose the datagridview cellClick Event
and check for the row index if its greater than one it means the clicked content is not the header

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
'If the click is noit for a header cell
If e.RowIndex > -1 Then
'Do your thing here if you want
End If

End Sub


Hope this helps
Cheers

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

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