Datagridview column header formatting

S

Steve

Hi All

I am using VB.net 2005 windows forms

I use the Datagridview.cellformatting event to change the colours of
individual cells as required and all works fine

How can I do the same for the datagridview column headers?
I would like to change the forecolor value for individual column headers as
required, so the Headertext displays in the required colour

There is no columnheader cellformatting event that I can find

Regards
Steve
 
J

Jeffrey Tan[MSFT]

Hi Steve ,

I think you can change individual header cell text color by using the code
snippet below:

Private Sub Form1_Load(sender As Object, e As EventArgs)
Me.dataGridView1.EnableHeadersVisualStyles = False
Me.dataGridView1.Columns(0).HeaderCell.Style.ForeColor = Color.Blue
End Sub 'Form1_Load

We should set DataGridView.EnableHeadersVisualStyles to false so that
XP/Vista theme will not be used to paint the header cell style.

If you want to perform advanced customization to header cells in the
DataGridView, you should handle DataGridView.CellPainting event and provide
customized painting code when DataGridViewCellPaintingEventArgs.RowIndex
equals -1(which means the header row). The link below contains sample code:
"How to: Customize the Appearance of Cells in the Windows Forms
DataGridView Control"
http://msdn.microsoft.com/en-us/library/hta8z9sz.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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