New to Telerik UI for WinForms? Start a free 30-day trial
Formatting Data Rows
Updated over 6 months ago
Use the RowFormatting event to apply custom formatting to RadVirtualGrid's data rows. The code snippet below demonstrates changing the ForeColor, BackColor and GradientStyle in all data rows where the cell value in the ContactTitle column is Owner:

C#
private void radVirtualGrid1_RowFormatting(object sender, VirtualGridRowElementEventArgs e)
{
VirtualGridCellElement contactTitleCell = radVirtualGrid1.VirtualGridElement.GetCellElement(e.RowElement.RowIndex, 3, radVirtualGrid1.MasterViewInfo);
if (contactTitleCell != null && contactTitleCell.Value != null && contactTitleCell.Value.ToString() == "Owner")
{
e.RowElement.DrawFill = true;
e.RowElement.BackColor = Color.Yellow;
e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.RowElement.ForeColor = Color.Red;
}
else
{
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}
}
Due to the UI virtualization in RadVirtualGrid, row elements are created only for currently visible rows and are being reused during operations like scrolling, filtering, sorting and so on. In order to prevent applying the formatting to other columns' row elements (because of the row reuse) all customization should be reset for the rest of the row elements.