Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Underline DataGridView column caption
Message
From
14/03/2008 09:28:40
 
 
To
10/03/2008 13:52:36
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01300582
Message ID:
01302101
Views:
8
This message has been marked as the solution to the initial question of the thread.
How about this:

using System.Drawing ;
foreach (DataGridViewColumn col in grid.Columns)
{
if (col.HeaderCell.Style.Font != null)
col.HeaderCell.Style.Font = new Font(col.HeaderCell.Style.Font, FontStyle.Underline);
else
col.HeaderCell.Style.Font = new Font(grid.DefaultCellStyle.Font, FontStyle.Underline);
}


>I need to underline column caption when user click in column header.
>In click event I tried
>
>foreach (DataGridViewColumn dataGridViewColumn in grid.Columns) {
> DataGridViewCellStyle dgvcellStyle = new DataGridViewCellStyle();
> System.Drawing.Font font = new System.Drawing.Font(
>dataGridViewColumn.HeaderCell.Style.Font,
> System.Drawing.FontStyle.Underline );
> dgvcellStyle.Font = font;
> dataGridViewColumn.HeaderCell.Style = dgvcellStyle;
> }

>
>But got exception probably since debugger shows that
>
>dataGridViewColumn.HeaderCell.Style.Font
>
>is null.
>
>dataGridViewColumn.HeaderCell.Style is not null.
>
>How to fix ?
>
>Andrus.
>
>Exception details which occurs:
>
>System.NullReferenceException was unhandled
> Message="Object reference not set to an instance of an object."
> Source="System.Drawing"
> StackTrace:
> at System.Drawing.Font..ctor(Font prototype, FontStyle newStyle)
> at myapp.BrowseForm`1.QueryData(Kontekst ko)
>...
Previous
Reply
Map
View

Click here to load this message in the networking platform