This is a migrated thread and some comments may be shown as answers.

Programmatically alter Header font?

3 Answers 886 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 31 Oct 2007, 05:24 PM
Hey Guys,

I've been trying to alter the font of the column header text. (Bold it if the column is required) based on a flag in the data.  This must be done once the data has been loaded, and the requiredness of fields will change.

So 2 questions.....
1) Is there a way to set the Header font (bold/not bold) programmatically?
2) What event should I be using to capture databinding?
   The obvious DataBindingComplete event is not firing when I execute this code: DataGridView1.DataSource = list;
    BindingContextChanged is fired multiple times, but when DataGridView1.DataSource is inspected and is always null...
     So I'm a bit confused about the events...

thanks!!

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 01 Nov 2007, 12:46 PM
Hello Mike,

Thank you for this question.

Yes, you can access the header row and change its font programmatically. You can do that by accessing the TableHeaderRow property of the GridViewTemplate class. Refer to the following sample:

GridViewCellInfo cell = this.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells["Third"]; 
cell.CellElement.Font = new Font(SystemFonts.DialogFont, FontStyle.Bold); 

Currently, the formatting will be lost if you change the grid grouping. This is a known issue and we will provide a solution in our next release.

The DataBindingComplete event is the right event for monitoring changes in DataSource. Unfortunately, it is fired only during form initialization inside InitializeComponent method. Our upcoming release will address this issue.

We have added 500 points to your telerik points account. Do not hesitate to contact us if you have any other questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mick
Top achievements
Rank 1
answered on 02 Aug 2013, 02:10 PM
I tried setting the header font to bold using the MasterGridViewInfo. vb said that it was obsolete and to use MasterView. I tried that and could not get to the header font. How should that be done now.

Thanks,
Mick Mathews
0
Paul
Telerik team
answered on 07 Aug 2013, 09:25 AM
Hello Mick,

Thank you for writing.

The best way to set the font of the header is in ViewCellFormatting event:
Dim newFont As New Font("Arial", 12.0F, FontStyle.Bold)
 
Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
    If TypeOf e.CellElement Is GridHeaderCellElement Then
        e.CellElement.Font = newFont
        e.CellElement.ForeColor = Color.Red
    End If
End Sub
I have attached a sample project for your reference.

Hope that helps. Please let us know if we can assist you further.

Regards,
Paul
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Jack
Telerik team
Mick
Top achievements
Rank 1
Paul
Telerik team
Share this question
or