473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagridview column header formatting

Hi All

I am using VB.net 2005 windows forms

I use the Datagridview.ce llformatting 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
Jun 27 '08 #1
2 10608
Hi Steve ,

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

Private Sub Form1_Load(send er As Object, e As EventArgs)
Me.dataGridView 1.EnableHeaders VisualStyles = False
Me.dataGridView 1.Columns(0).He aderCell.Style. ForeColor = Color.Blue
End Sub 'Form1_Load

We should set DataGridView.En ableHeadersVisu alStyles 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.Ce llPainting event and provide
customized painting code when DataGridViewCel lPaintingEventA rgs.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:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #2
Jeffrey

Thanks for the help

Solved the problem

Regards
Steve
""Jeffrey Tan[MSFT]"" <je***@online.m icrosoft.comwro te in message
news:Dh******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Steve ,

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

Private Sub Form1_Load(send er As Object, e As EventArgs)
Me.dataGridView 1.EnableHeaders VisualStyles = False
Me.dataGridView 1.Columns(0).He aderCell.Style. ForeColor = Color.Blue
End Sub 'Form1_Load

We should set DataGridView.En ableHeadersVisu alStyles 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.Ce llPainting event and
provide
customized painting code when DataGridViewCel lPaintingEventA rgs.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:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 27 '08 #3

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

Similar topics

2
9660
by: David Veeneman | last post by:
How can I set a bound DataGridView control to use a dataset table's column captions, instead of column names? I'm working with a DataGridView control, which I have bound to a table in a dataset. The dataset is created at run time, so I don't know column headers in advance. The table's column captions are set at run time, using the...
1
4690
by: mark carew | last post by:
Hi, Problem - An extra column to the left (even with row headers disabled) ---------------------------------------------------------- Apologies if this posting is already in the newsgroup; but have changed to 40tude and can't see it in the newly dowloaded messages. It was originally html (tut tut) so maybe it didn't register. I have tried...
5
21322
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net help system and can't find any help on formatting text. There's plenty of help formatting numbers, dates, and times, though. I'm in the phase of...
2
7418
by: Rich | last post by:
Hello, Some database applicatins have a tooltip feature where when you are dragging the scrollbar of the table view a tooltip appears next to the mouse cursor displaying the approximate record number you are scrolling past (Excel, Access). Sql server has the rownumbers on the Row Header column of its table view. Ideally, I would like to...
3
7791
by: Prashwee | last post by:
Hello All In my windows application I am using DataGridView as my grid control. I populated let's say 10 rows of data and modified 3 random rows. I need to put some sort of Edit Marker in the row header. This can be an image. Please any one share a code for this implementation. If i were to save this records, how can I trap those 3...
8
11514
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a combo box column. Data binding is working fine for the first two columns. I am able to edit values and persist them back to the bound object and...
4
19782
by: NvrBst | last post by:
I have a log viewer. I sort the DataGridView by the Time Column and then run a function to set all cell backcolors depending if the cell above is different. This works correctly, however, when I resort a column (by clicking any of the column headers) then all the colors revert back to the origional white background. Is there a way to...
3
215
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 the column highlight in yellow. Where the row and column intersect, I'd like the cell to take on a red color. It's synonymous to a grid matrix...
1
5116
by: Ben456 | last post by:
Hello, I'm trying to figure out how to keep my cell formatting the same even after I've clicked a column sort header. Basically I've programmatically changed forecolors and backcolors of several different cells in my datagridview. When I the click the sort header it resorts the data but all my color formatting is lost. Is there a way...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.