# UI Virtualization

**RadGridView** uses virtualization for its cells and rows. To put it simply, this means that when binding to a DataTable with 1000 rows, you get 1000 data row objects created in RadGridView (of type **GridViewDataRowInfo**). However, not all data row objects can be visible at the same time in the RadGridView estate area in your application. This is why only the visual rows that can be shown in the estate area get created (these visual rows are of type **GridDataRowElement**), or about 20-30 rows for an average application with medium-sized RadGridView. These visual elements are reused during scrolling, filtering and other operations with the grid, meaning dramatically improved performance and memory footprint as only a small number of visual items are created.

## Formatting Events

Because of the virtualization you cannot access UI elements at design time or directly by using the element tree or a property. Instead, you have to use formatting events. These events in RadGridView are **CellFormatting** for data cells and **RowFormatting** for data rows. When customizing system rows and cells, one should use **ViewCellFormatting** and **ViewRowFormatting** events instead. [Read more](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/cells/formatting-cells)

Here is a quick sample:

```C#
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.Name == "UnitsOnOrder" && e.CellElement.Value != null)
    {

        if ((short)e.CellElement.Value <= 0)
        {
            e.CellElement.DrawFill = true;
            e.CellElement.GradientStyle = GradientStyles.Solid;
            e.CellElement.BackColor = Color.Red;
            e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);

    }

}
```

```VB.NET
Private Sub radGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
    If e.CellElement.ColumnInfo.Name = "UnitsOnOrder" AndAlso e.CellElement.Value IsNot Nothing Then

        If CShort(Fix(e.CellElement.Value)) <= 0 Then
            e.CellElement.DrawFill = True
            e.CellElement.GradientStyle = GradientStyles.Solid
            e.CellElement.BackColor = Color.Red
            e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder
        Else
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local)
            e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local)
        End If
    Else
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
        e.CellElement.ResetValue(VisualElement.BackColorProperty, ValueResetFlags.Local)
        e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local)

    End If

End Sub
```

![WinForms RadGridView Formatting events](https://www.telerik.com/products/winforms/documentation/assets/fa4aba1d47f0e046d335b7c1f1ede768/gridview-fundamentals-ui-virtualization001.png)

## Style property

Another solution is the **Style** property which is available when accessing logical cell objects. It allows for directly setting visual properties that will reflect the specified cell element. [Read more](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/cells/formatting-cells)

## Conditional formatting

Another feature that we provide is the conditional formatting which is available for end user via context menu. [Read more](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/cells/conditional-formatting-cells)

## See Also

* [Binding the Grid](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/binding-the-grid)

* [Columns](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/columns)

* [Creating Hierarchical Grids](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/creating-hierarchical-grids)

* [Editing](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/editing)

* [Element Hierarchy](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/element-hierarchy)

* [Key Features](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/key-features)

* [Keyboard Support](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/keyboard-support)

* [Logical vs. Visual Grid Structure](https://www.telerik.com/products/winforms/documentation/controls/gridview/fundamentals/logical-vs.-visual-grid-structure)
