Edit this page

Logical vs. Visual Grid Structure

The grid can be thought of in terms of both logical and visual. The logical layer allows you to traverse grid meta data and data, i.e. templates, groups, columns, rows and cells. The visual aspect of the grid deals with the Telerik Presentation Foundation (TPF) elements that are drawn on the screen. RadGridView events such as CellFormatting allow you to manipulate the visual aspect of the grid.

Logical Grid Structure

RadGridView has a logical structure that uses collections of objects such as GridViewRowInfo and GridViewCellinfo to represent elements of the grid. The outline below shows the general structure of the logical layer:

Where hierarchical data is shown in the grid, the structure changes slightly:

This logical tree structure allows you to traverse down through the cell level using RadGridView collections. For example, to traverse starting at the MasterTemplate rows and through every cell to perform some arbitrary operation:

Iterate the MasterGridViewTemplate cells

foreach (GridViewRowInfo rowInfo in radGridView1.MasterTemplate.Rows)
    foreach (GridViewCellInfo cellInfo in rowInfo.Cells)
        if (cellInfo.ColumnInfo.HeaderText == "Name")
        cellInfo.Value = "TestName";

For Each rowInfo As GridViewRowInfo In RadGridView1.MasterTemplate.Rows
    For Each cellInfo As GridViewCellInfo In rowInfo.Cells
        If cellInfo.ColumnInfo.Name = "Name" Then
            cellInfo.Value = "TestName"
        End If

...or to iterate all the columns of each child template within the master template:

Iterate the child templates cells

foreach (GridViewTemplate childTemplate in radGridView1.MasterTemplate.Templates)
    foreach (GridViewColumn column in childTemplate.Columns)
        column.HeaderTextAlignment = ContentAlignment.TopCenter;

For Each childtemplate As GridViewTemplate In RadGridView1.MasterTemplate.Templates
    For Each column As GridViewColumn In childtemplate.Columns
        column.HeaderTextAlignment = ContentAlignment.TopCenter

Visual Grid

RadGridView uses virtualization for its visual elements. This means that only the rows that are currently visible have a visual element. When the grid is scrolled up and down the visual elements are reused. For example, because of the virtualization, the CellElement can only be accessed inside the CellFormatting event and only for the current cell. The CellFormatting event is fired every time when the cell's visual state needs to be updated.

RadGridView has several events that allow you to access the visual elements of the grid: CreateCell, CellPaint, RowPaint, CellFormatting and RowFormatting. These events pass references to TPF elements that represent rows and cells.

See Also

Was this article helpful? Yes No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article