Programmatically alter Header font?

4 posts, 0 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Oct 2007

    Posted 31 Oct 2007 Link to this post

    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...

  2. Jack
    Jack avatar
    2333 posts

    Posted 01 Nov 2007 Link to this post

    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,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Mick
    Mick  avatar
    5 posts
    Member since:
    Mar 2013

    Posted 02 Aug 2013 Link to this post

    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.

    Mick Mathews
  4. Paul
    Paul avatar
    60 posts

    Posted 07 Aug 2013 Link to this post

    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.

    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 >>
Back to Top