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

Formatting Rows

Customize the appearance of data rows

Use the RowFormatting event to apply custom formatting to RadGridView's data rows.

The code snippet below demonstrates changing the background color of rows, which "BMP" cell value is set to true:

WinForms RadGridView Formatted Rows

private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    if ((bool)e.RowElement.RowInfo.Cells["BMP"].Value == true)
    {
        e.RowElement.DrawFill = true;
        e.RowElement.GradientStyle = GradientStyles.Solid;
        e.RowElement.BackColor = Color.Aqua;
    }
    else
    {
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
    }
}

An if-else statement is used to reset the value of BackColorProperty if no drawing is required.

You should set DrawFill to true to turn on the fill for the row (depends on the used theme).

Please refer to the Fundamentals topic for more information about the UI Virtualization.

Customize the Non-Data Rows Appearance

To customize the non-data rows (header row, new row, filtering row, etc) of RadGridView, you need to handle the ViewRowFormatting event.

void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{

    if (e.RowElement is GridTableHeaderRowElement)
    {
        e.RowElement.DrawFill = true;
        e.RowElement.BackColor = Color.Navy;
        e.RowElement.NumberOfColors = 1;
        e.RowElement.ForeColor = Color.White;
    }
    else
    {
        e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
        e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
    }
}

WinForms RadGridView Customized Non-Data Rows