Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have binded data to datagridview.

It works fine but my problem is that when I place my mouse pointer over column header it automatically get highlighted with blue color.

How to disable that automatic highlighting when mouse pointer is place over the column header

How to get rid of this problem
Posted
Updated 4-Oct-22 10:49am

hope this helps u

DataGridView1.DefaultCellStyle.SelectionBackColor = DataGridView1.DefaultCellStyle.BackColor
DataGridView1.DefaultCellStyle.SelectionForeColor = DataGridView1.DefaultCellStyle.ForeColor
 
Share this answer
 
Try to set DataGridView.EnableHeadersVisualStyles to False.
 
Share this answer
 
Comments
John . Peak 1-Nov-23 8:07am    
Thanks a lot!
It works for me! I've just switched from 4.6 to 4.8 and this sh*t happened
Both solutions 2 and 3 were usefull
The question was asked 8 years ago, but I have an answer for it now in 2022.

Here's the deal. I upgraded my Windows Forms app (which uses a DataGridView) to use .NET 4.8.
I didn't change anything else in the app, but suddenly when I click an item in the DataGridView it automatically highlights the COLUMN HEADER in dark blue.

Previous versions of .NET did not do this to DataGridView.

I had to find a way around this annoying behavior.

I discovered that all I had to do when I initialize the DataGridView is:
(just set the SelectionBackColor to be the current BackColor of the datagridview)
C#
YourDataGridView.ColumnHeadersDefaultCellStyle.SelectionBackColor = YourDataGridView.ColumnHeadersDefaultCellStyle.BackColor;


Fixed!
 
Share this answer
 
Comments
Richard Deeming 6-Oct-22 5:46am    
Isn't that almost the same as solution 1 though? You're just using ColumnHeadersDefaultCellStyle instead of DefaultCellStyle. (The 1-vote wasn't me, BTW.)
John . Peak 1-Nov-23 8:08am    
Thanks a lot!
It works for me! I've just switched from 4.6 to 4.8 and this sh*t happened
Both solutions 2 and 3 were usefull

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900