.NET Framework - Datagridview column header formatting

Asked By Steve on 22-May-08 10:06 PM
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




jeta replied on 23-May-08 02:48 AM
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:
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:
msdnmg@microsoft.com.

==================================================
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.
Steve replied on 23-May-08 07:32 PM
Jeffrey

Thanks for the help

Solved the problem

Regards
Steve