473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DATAGRIDVIEW - detect Header click

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
Aug 3 '07 #1
1 26240
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
Aug 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: milk-jam | last post by:
I'm trying to set my datagridview so that the first row will be left blank and to use it as a filtering filed for the datagridview. Until now I was using 2 datagridview the upper one with a header...
1
by: Nathan Franklin | last post by:
I have a DataGridView on my windows form and I am trying to enable buttons on a toolbar when the DataGridView's GotFocus is called and then disable with LostFocus(). The problem is I can only get...
0
by: Code Monkey | last post by:
In project there is a DataGridView. I have a little bit of code that I which displays information based on the cell that was clicked. My problem is how to detect if the user clicked on a...
0
by: DBC User | last post by:
Hi, I have a datagridview, with column header and on the lefthandside the rowselector. I would like to do the following 2 1. When the user click ONLY the row selector or inside the gridview...
7
by: Rainer Queck | last post by:
Hi NG, Why is it, that in my DataGridView all columns which are not bound to a "DataProperty" loos thier content in a couple of occasions? This happens if: - Underlaying...
2
by: Rick | last post by:
VS 2005/Pro I'm using a DataGridView in a Windows form and allowing the user to sort the columns by clicking on the header column. Is there some method offered by the grid to return back to...
1
by: PawelR | last post by:
Hi Group, In my application I have DataTable which is displayed in DataGridView via DataView: DataView myView = new DataView(myTable); myDataGridView.DataSource = myView; One column im...
3
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I'm creating a control derived from DataGridView. I'd like the user to click a row and have the row highlight in yellow. I'd then like the user to click a column and have...
0
by: Queez | last post by:
OK, this is rediculous... Surely, sorting should be one of the easiest things with the ASP.NET DataGridView control. I mean, there's hundreds of sites out there (Microsoft MSDN entries included)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.