New to Telerik UI for WinForms? Start a free 30-day trial
Apply Formatting Only To Cells in a Child Template
Updated on Sep 14, 2026
In a hierarchical RadGridView, a cell belongs to a child template when its ViewTemplate.Parent property is not null. Use this condition in a ViewCellFormatting event to limit visual changes to child templates only.
Example 1: Format Data Cells in Child Templates
Use the following example to change the BackColor of data cells in child templates only:
C#
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;
}
}Example 2: Set the Header Height in a Child Template
Use the following example to change the header height of the first-level child template:
C#
void radGridView1_ViewCellFormatting1(object sender, CellFormattingEventArgs e)
{
if (e.CellElement.ViewTemplate.Parent != null)
{
e.CellElement.TableElement.TableHeaderHeight = 100;
}
}Example 3: Highlight Header Cells in Child Templates
Use the following example to change the background color of header cells and highlight them only in child templates.
C#
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement is GridHeaderCellElement && e.CellElement.ViewTemplate.Parent != null)
{
e.CellElement.DrawFill = true;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.BackColor = Color.LightYellow;
}
else if (e.CellElement is GridHeaderCellElement)
{
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}