Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Underline DataGridView column caption
Message
From
10/03/2008 13:52:36
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
Underline DataGridView column caption
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01300582
Message ID:
01300582
Views:
90
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)
...
Andrus
Next
Reply
Map
View

Click here to load this message in the networking platform