Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Underline DataGridView column caption
Message
De
14/03/2008 09:28:40
 
 
À
10/03/2008 13:52:36
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01300582
Message ID:
01302101
Vues:
7
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)
>...
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform