Resolved DataGridView Row Header color

amnon

Member
Joined
Dec 18, 2022
Messages
12
Programming Experience
Beginner
hello,

Is it possible to remove selection from Row Header and Column Header ? or at least use the same color as selection?
I tried changing the selection color by setting

VB.NET:
        DataGridView1.ColumnHeadersDefaultCellStyle.SelectionBackColor = Color.Black
        DataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Black
 
You have to set this to False to change header colors:
VB.NET:
grid.EnableHeadersVisualStyles = False
Dim rowheadStyle = grid.RowHeadersDefaultCellStyle
rowheadStyle.SelectionBackColor = rowheadStyle.BackColor
 
This is an example of why you should ALWAYS read the documentation if something doesn't work the way you expect. The documentation for the DataGridView.ColumnHeadersDefaultCellStyle property says this:
If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.
which would have answered your question immediately in the same way. You can go directly from VS to the documentation for any type or member using the F1 key (context-sensitive Help) and you should have the documentation home page bookmarked/favourited in your browser. Here is the Australian version I use, so you can just change the culture appropriately. You'll be able to answer many of your own questions using the documentation and you'll learn lots of other stuff besides. We'll still be here for the stuff you can't find or can't understand.
 

Latest posts

Back
Top