Change font for one column in RadGridView on runtime (VB.net)

2 posts, 0 answers
  1. ISB-developer
    ISB-developer avatar
    21 posts
    Member since:
    Jul 2011

    Posted 02 Nov 2011 Link to this post

    Hi
    I need to change the font for one column of my RadGridView in runtime. Is this possible?
    If Yes, can you help me with the code in VB.NET?
    Thanks
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 03 Nov 2011 Link to this post

    Hi Isb-Developer,

    Thank you for writing.

    You can use the CellFormatting event of the RadGridView. Consider the following code snippet which demonstrates this:

    Private m_boldFont = New Font("Helvetica", 10, FontStyle.Bold)
     
    Public Sub New()
      InitializeComponent()
      AddHandler Me.RadGridView1.CellFormatting, AddressOf RadGridView1_CellFormatting
    End Sub
     
    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
      If e.ColumnIndex = 1 Then
        e.CellElement.Font = Me.m_boldFont
      Else
        e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local)
      End If
    End Sub

    Note that the creation of a Font is a heavy operation and can lead to memory leaks. It is best to create one font and use it across the application.

    I hope this will help you. If you have further questions, I would be glad to help. Best wishes,
    Ivan Petrov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top