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

Force CellFormatting to Update Font at Runtime

2 Answers 398 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 01 Sep 2009, 08:59 PM
Goal: I need be able to set the font size of a grid's cells at runtime based on user input.
Design: I have a user control with a telerik RadGrid on it.  The grid has a mixture of datacolumns and imagecolumns.  The user control exposes a property called FontSize.
Problem: I can't get Grid_CellFormatting to be hit once the FontSize Property is changed.  

I need some way to force the grid to reformat all the cells when the FontSize Property is set.
I can mouse over the cells which causes Grid_CellFormatting to fire, at which time the cell font is updated with the new font size, but i need this to happen programatically.

My User Control:

  Private Sub Grid_CellFormatting(ByVal sender As Object, _ 
        ByVal e As CellFormattingEventArgs) _ 
        Handles grid.CellFormatting 
        Dim f As New System.Drawing.Font("Arial", My.Settings.Grid_FontSize, _ 
            System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) 
        e.CellElement.Font = f 
    End Sub 


    Public Property FontSize() As Single Implements IReportGridView.FontSize 
        Get 
            Return My.Settings.Grid_FontSize 
        End Get 
        Set(ByVal value As Single
            My.Settings.Grid_FontSize = value 
            My.Settings.Save() 
            My.Settings.Reload() 
        End Set 
    End Property 


I've tried adding me.grid.Update, Me.grid.Refresh after the My.settings.reload, but nothing seemed to trigger the CellFormatting event.

Your help is appreciated.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 04 Sep 2009, 11:45 AM
Hello Matt,

In order to fire the CellFormatting event programmatically, you should call the Update method of the GridElement, passing the StateChanged parameter:
Public Property FontSize() As Single Implements IReportGridView.FontSize    
        Get    
            Return My.Settings.Grid_FontSize    
        End Get    
        Set(ByVal value As Single)    
            My.Settings.Grid_FontSize = value    
            My.Settings.Save()    
            My.Settings.Reload()    
            Me.RadGridView1.GridElement.Update(GridUINotifyAction.StateChanged)  
        End Set    
    End Property    
 

If you have additional questions, feel free to contact me.

Greetings,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matt
Top achievements
Rank 1
answered on 04 Sep 2009, 02:52 PM
Excellent! we're off and rolling again.  Thank you for the response.
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Matt
Top achievements
Rank 1
Share this question
or