Windows Develop Bookmark and Share   
 index > Windows Forms General > Changing Font in DataGridView - problem
 

Changing Font in DataGridView - problem

Hi,

I tried to change header font for a datagridview, and that appeared Properly in the design view.

But when I see in runtime, header is shown with the Arial font, what ever be the font assigned.

but for cell fonts, the first row appears in Arial, and the others in the changed font style.

Tried many times. But No result.

I tried for columnheadersrowstyle, defaultcellstyle, etc.,

what mistaking I doing.

regards,

Mohan Raj K.

Mohanraj_k  Tuesday, June 26, 2007 2:20 PM

Hi, Mohanraj_k

Please try the following codes to see if theywill work.


Code Snippet
DataTable dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Rows.Add("ab", "cd");

dataGridView1.DataSource = dt;
dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Arial", 20);

Hope this helps.

Regards

Yu Guo â€?MSFT  Thursday, June 28, 2007 2:59 AM

Hi, Mohanraj_k

Please try the following codes to see if theywill work.


Code Snippet
DataTable dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Rows.Add("ab", "cd");

dataGridView1.DataSource = dt;
dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Arial", 20);

Hope this helps.

Regards

Yu Guo â€?MSFT  Thursday, June 28, 2007 2:59 AM

Hi,

Thanks for your reply.

I tried to change the font programatically. and it is working. Thanks.

I don't know what is happening inside.

Actually I tried to set the font in design time. and it is showing correctly. but when in runtime it only showed the ARIAL font ( instead of VERDANA).

Also saved it, and closed the project. and when i reopened the project, the fonts are again become ARIAL (instead of VERDANA). I noticed this many time for the past two days.

After your reply. When i Opened and the font was the same ARIAL. And I tried to changed it in programmatic way, it wasworking.

But todayIset in the design time. and it is working in the runtime also. and I tried many time closing and opening, the font got set.

Can I Know what happened actually ? Is that some background work files got locked and that was the reason not to set the font?

Hey,

I met these kind of problems previously itself, some four to five times. But Microsoft Unanswered for some of these kind of posts.( please see my previous posts).

1. Once I got problem with setting the combo box column in a DGV column.All the Column type elements apeared twice.

2. Once I got a problem like when resizing the objects, that was larger than the size of the showing design window. it doesn't properly resizes as we expect, but actually sets to the (top or bottom of the design window)least or the farther.

And again THANKS for your reply

Mohan Raj K.

Mohanraj_k  Thursday, June 28, 2007 1:08 PM

Hi, Mohanraj_k,

I'm glad that my reply works for your problem.

However, for your further problem which does not happen regularly, I am afraid we cannot find out the exact root cause without further information captured when the problem occurs. On the other hand, based on my past experience, I guess it can be the following:

1. Have you applied the latest service pack? If not, please apply the latestservice pack.

2. If you reboot the operating system to safe mode, do you have the sameproblem? This can help to isolate whether any other applications are interfering with Visual Studio. Note that some features (like IIS) are not available under safe mode. Please check whether this can apply or not. In addition to safe mode, we can also suggest “clean boot� http://support.microsoft.com/kb/310353.

3. If you create a new user account, doyou have the problem? This can help to isolate user profile corruption related causes.

4. If you disable Add-ns (e.g. “Tools�| “Add-in Manager� and run “devenv.exe /safemode� do you still have the problem? This can eliminate the possibility that third party Add-ins are causing problems.

5. If you create a new project, do you have the problem? Sometimes corrupted project settings can cause problems. These are project specific.

Besides, I do recommend you to reinstall your .Net framework and Visual Studio to check if your problem shows up again.

Hope this helps,

Regards

Yu Guo â€?MSFT  Friday, June 29, 2007 5:51 AM

You can use google to search for other answers

Custom Search

More Threads

• Best way to get (and set) a radio button in GroupBox Control?
• How can I use IViewObject::Draw into a System.Drawing.Image
• how to make a treeview show an image for some nodes but not others?
• how to change font color on tabpage
• How can I set the cursor to the last row of DataGrid?
• Passing Parameters during a Call
• Media player
• Retrieving text width, length, x, y after drawstring
• textbox multiple selected text
• c# form to crstal report