Why does my ColumnHeadersDefaultCellStyle keep being reset in Visual Studio designer?

c# datagridview defaultcellstyle format
vb net datagridview column header font size
datagridview defaultcellstyle format not working
c# datagridview column font bold
c# datagridview header font size
c# datagridview column header alignment
cell styles in the windows forms datagridview control
datagridview cell types

I am trying to make the column headers of my DataGridView bold, in Visual Studio 2008.

Every time I change my ColumnHeadersDefaultCellStyle to Calibri 9.75pt bold, using the properties box, the next time I reopen the saved form, the ColumnHeadersDefaultCellStyle has reverted to Calibri 9.75 without bold.

My form's font is Calibri 9.75 without bold, as is my default cell style, but I should be able to override the default cell style with my ColumnHeader style right?

I can solve this problem programmatically by setting the style when the form is shown, but we would like to have the Visual Studio designer show the bolded headers, so we can layout the columns appropriately for the space taken up by bold header text.

In addition, the actual designer file specifies that the ColumnHeadersDefaultCellStyle is bold, even though the designer interface says it is not bold.

dataGridViewCellStyle1.Font = new System.Drawing.Font("Calibri", 9.75F,  
    System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;

this.receiptDetailView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;

Have you tried check EnableHeadersVisualStyles value?

According to MSDN:

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.

DataGridView: DefaultCellStyle and ColumnHeaderDefaultCellStyle , Visual Studio 2010 C++ CLR Managed Forms Application, regarding the GUI designer. This is a weird issue. In my project I have to keep� I have a somewhat complex UserControl, and Visual Studio 2008 is giving me a rather harmless annoyance when working with it. Every single time I open the control with the Designer, it decides to immediately change some of the harmless values set by the designer - namely the initialization of Size properties.

It is a bug, although Microsoft would probably try to call it a feature. The DataGridView header cells are supposed to inherit the current theme only if EnableHeadersVisualStyles is set to TRUE, and use the settings in ColumnHeaderDefaultCellStyles if it is false. But the DGV ignores EnableHeadersVisualStyles and always inherits the font of the parent container it resides in.

Both rutlean's and Nico Engler suggestions will work. Here is what I always do as a standard practice: Put your DGV in a panel (depending on your application, you might want to set the Dock property to fill. Then set the Panel's font to your desired settings. Your DGV will now always inherit that setting.

Set Default Cell Styles and Data Formats for DataGridView Control , The DataGridView control lets you specify default cell styles and cell data formats for Row Styles for the Windows Forms DataGridView Control Using the Designer. next to the DefaultCellStyle, ColumnHeadersDefaultCellStyle, If visual styles are enabled, the row and column headers (except for the� Why does my ColumnHeadersDefaultCellStyle keep being reset in Visual Studio designer? Visualizing trees in VS2008 ; Visual Studio-Is there simple way to add 'Close Solution" to r-click in Solution Explorer

It seems that this is a bug, though I am not sure why it happens. I have tested it in every possible way and the value is overriden by the parent control value regardless of whether it is set or not. This is the opposite of how every other WinForms (or any other UI framework) control works, and doesn't make any sense. I have also tested various other controls and have not found another case where this happens.

The ColumnHeadersDefaultCellStyle Font only matters if the Font property is not set on the parent control (form in this case).

I am giving the bounty to the most upvoted answer but that is not what's going on here.

The "solution" to this that I've been using is to set the font again in the form load event, however this is not a perfect solution since such code doesn't belong there.

DataGridView.ColumnHeadersDefaultCellStyle Property (System , If visual styles are enabled and EnableHeadersVisualStyles is set to true , all header cells except the TopLeftHeaderCell are painted using the current theme and� 21 Why does my ColumnHeadersDefaultCellStyle keep being reset in Visual Studio designer? 11 The imported project "C:\Microsoft.CSharp.targets" was not found 11 Django template ifequal comparison of decimals

I ran into this same issue. However, my dataGridView is located in a groupbox. On a restart of VS 2010, the dataGridView fonts will always be whatever the groupBox is set to. Definitely a bug I would like.

关于winforms:为什么我的ColumnHeadersDefaultCellStyle总是在 , Why does my ColumnHeadersDefaultCellStyle keep being reset in Visual Studio designer?我试图在Visual Studio 2008中使DataGridView的列� I am trying to make the column headers of my DataGridView bold, in Visual Studio 2008. Every time I change my ColumnHeadersDefaultCellStyle to Calibri 9.75pt bold, using the properties box, the next time I reopen the saved form, the ColumnHeadersDefaultCellStyle has reverted to Calibri 9.75 without bold.

I resolved this problem by adding a frame. For me, the datagridview was inside a groupbox (although a few other container types did the same).

Resolved by putting a panel inside the groupbox, set the appropriate font to that panel, put the datagridview inside that panel and by default it inherits the fonts.

I am using VS2010

为什么我的ColumnHeadersDefaultCellStyle会继续在Visual Studio , Why does my ColumnHeadersDefaultCellStyle keep being reset in Visual Studio designer? 发表于 2012-07-11 18:46:03. 活跃于 2019-03-16 01:29:07. In this article I’ll show you how to configure a table tablix to both repeat column headers at the top of every page and freeze them while scrolling. While tablixes have properties for these things, they only work in matrix tablixes but not in tables. I’ll show you a way to accomplish these things using an approach that does work; however, be warned: the way to do this is clunky, counter

C# Windows Forms, Gets or sets which cell has the focus. Not available at design time. CurrentRowIndex, Gets or sets index of the selected row. DataMember, Gets or sets the specific� Instead, if you want to have meaningful column header names, you can do the following. Click in the first row of the worksheet and insert a new row above that first row.; In the inserted row, enter the preferred name for each column.

DataGridView in Windows Forms – Tips, Tricks and Frequently , DataGridView control is a Windows Forms control that gives you the ability to If the columns being retrieved from the database do not have� Edit: Thanks for the visual styles suggestion, but that won't cut the mustard unfortunately (in fact Enable Visual Styles is the default in Visual Studio 2008) the XP look and feel winforms controls still use the microsoft sans serif font by default.

Visual studio 2019 is not resetting Fonts and Colors, Change color theme, stop - restart VS 2019 -> colors are as before change theme . Its a little bit annoying, because over the years I got used to a�

Comments
  • I have the same problem. ColumnHeadersDefaultCellStyle font keeps reverting to non-bold. When I recompile the project, it changes from Bold to Regular in the designer code on its own. Have you maybe found a solution?
  • Closing/reopening the file also reverts it to non-bold. When I change to bold and save, I can actually see FontStyle.Bold in the designer code, but it changes on its own when reloaded or compiled.
  • speedy.sh/KsREw/nobold.zip here is a basic project where this problem is apparent. Things done: added DGV to the form, added columns to the DGV, changed the form font to regular arial, changed the DGV columnheadersdefaultcellstyle font to bold arial, disabled visual styles.
  • I have Visual Styles disabled. :/
  • Ah sorry, I forgot to mention, I am using Visual Studio 2010. In VS2010, this does not work.
  • @svinja I tested this on visual studio 2010 ultimate and even setting values in property panel worked.copy the project and paste it somewhere else.delete all unnecessary files like .sdf etc and reload the project.Hope this wont let the bug remain.
  • The problem is that the form font (or any other) setting is only supposed to propagate to the datagrid column header styles if they aren't set (just like with every other winforms control). This is not the case here.
  • There is a difference when you applied font style to datagridview column header with other controls. When you say this.button1.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); it will use Font getter setter from Control class. But this dataGridViewCellStyle1.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); it's using Font from DataGridViewCellStyle class.
  • And seeing System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); gives me the idea that DataGridViewCellStyle is on namespace System.Windows.Forms which is the same namespace used by every Form there is. Which means their Font style declaration is in the same namespace.
  • Correct answer. Adjusting the parent font (in my case a GroupBox) was the only working solution. Thank you!