CellFormatting and ViewCellFormatting

ViewCellFormatting event is fired for all cells. If you want to format the grouping row or the header cells, you should use this event.

CellFormatting is called for each column in your row

Here's some code from a recent project. The idea is to show you how to format group and detail cells at the same time. This could also be used to format header cells. 

Dim myFont As Font
Select Case True
    Case TypeOf e.CellElement Is GridGroupContentCellElement
        'these are the group cells
 
        'get the native font for the cell
        myFont = e.CellElement.Font
 
        If e.CellElement.Text.Contains("Yard") Then
            'add 'bold' to the font, increase the font size
            myFont = New Font(e.CellElement.Font.FontFamily, 10, FontStyle.Bold)
            'color the cell
            e.CellElement.ForeColor = Color.CornflowerBlue
        Else
            'increase the font size
            myFont = New Font(e.CellElement.Font.FontFamily, 10, FontStyle.Regular)
            e.CellElement.ForeColor = Color.Black
        End If
        e.CellElement.Font = myFont
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
        e.CellElement.DrawFill = True
    Case TypeOf e.CellElement Is GridDataCellElement
        'gather data from the cells
        Dim bCommercial As Boolean = e.CellElement.RowInfo.Cells("blnCommercialJob").Value
        Dim dtRSD As Date = e.CellElement.RowInfo.Cells("ReqShipDate").Value
 
        Dim bSetBackColor As Boolean = False
        Dim bSetForeColor As Boolean = False
 
        'business logic
        If DateAdd(DateInterval.Day, -7, dtRSD) < Now Then
            bSetBackColor = True
        End If
 
        If bCommercial Then
            bSetForeColor = True
        End If
 
        If bSetBackColor Or bSetForeColor Then
            If bSetBackColor Then
                e.CellElement.BackColor = Color.Beige
            Else
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
            End If
            If bSetForeColor Then
                e.CellElement.ForeColor = Color.Maroon
            Else
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
            End If
            e.CellElement.DrawFill = True
            e.CellElement.NumberOfColors = 1
        Else
            'reset the values if this cell is not subject to our business logic
            e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
        End If
 
        'selectively enable/disable a command column
        If e.CellElement.ColumnInfo.Name.ToUpper = "CMDRELEASE" Then
            If e.CellElement.Value = "" Or App.IsSalesperson Then
                e.CellElement.Enabled = False
            Else
                e.CellElement.Enabled = True
            End If
        End If
    Case TypeOf e.CellElement Is GridHeaderCellElement
        'format header cells here
    Case Else
        'placekeeper
End Select

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences