New to Telerik UI for WinForms? Download free 30-day trial

Applying formatting only to cells in a child template

If the parent of the view template is not null, the cell element is located in a child template.

Example 1

This idea is used in the code snippet below so that the BackColor of the cells located only in the child templates is changed:

Changing the cells BackColor for cells located in a child template

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ViewTemplate.Parent != null)
    {
        e.CellElement.BackColor = Color.Yellow;
        e.CellElement.NumberOfColors = 1;
        e.CellElement.DrawFill = true;
    }
}

Private Sub RadGridView1_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
    If e.CellElement.ViewTemplate.Parent IsNot Nothing Then
        e.CellElement.BackColor = Color.Yellow
        e.CellElement.NumberOfColors = 1
        e.CellElement.DrawFill = True
    End If
End Sub

 Example 2

You can use the following code snippet to change the header height of the first level child template:

Changing the child template header row height

void radGridView1_ViewCellFormatting1(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ViewTemplate.Parent != null)
    {
        e.CellElement.TableElement.TableHeaderHeight = 100;
    }
}

Private Sub RadGridView1_ViewCellFormatting1(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting
    If e.CellElement.ViewTemplate.Parent IsNot Nothing Then
        e.CellElement.TableElement.TableHeaderHeight = 100
    End If
End Sub

See Also

In this article