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:
GridViewTemplate (MasterGridViewTemplate)
- RootGroup (RootGroups)
- Rows (GridViewRowInfo)
- Groups (DataGroup)
- Columns (GridViewColumn, GridViewDataColumn)
- Rows (GridViewRowInfo)
- ChildGridViewTemplates (ChildGridViewTemplates[])
Where hierarchical data is shown in the grid, the structure changes slightly:
GridViewTemplate
- RootGroup (contains many root groups - one for each row of the parent template)
- Rows
- Groups
- Columns
- Rows
This logical tree structure allows you to traverse down through the cell level using RadGridView collections. For example, to traverse starting at the MasterGridViewTemplate rows and through every cell to perform some arbitrary operation:
[C# ] Traversing Rows and Cells
foreach (GridViewRowInfo rowInfo in radGridView1.MasterGridViewTemplate.Rows)
{
foreach (GridViewCellInfo cellInfo in rowInfo.Cells)
{
cellInfo.Value = "Test";
}
}
[VB] Traversing Rows and Cells
For Each rowInfo As GridViewRowInfo In radGridView1.MasterGridViewTemplate.Rows
For Each cellInfo As GridViewCellInfo In rowInfo.Cells
cellInfo.Value = "Test"
Next
Next
...or to iterate all the columns of each child template within the master template:
[C#] Traversing Templates and Columns
foreach (GridViewTemplate childTemplate in radGridView1.MasterGridViewTemplate.ChildGridViewTemplates)
{
foreach (GridViewColumn column in childTemplate.Columns)
{
column.HeaderTextAlignment = ContentAlignment.TopCenter;
}
}
[VB] Traversing Templates and Columns
For Each childTemplate As GridViewTemplate In radGridView1.MasterGridViewTemplate.ChildGridViewTemplates
For Each column As GridViewColumn In childTemplate.Columns
column.HeaderTextAlignment = ContentAlignment.TopCenter
Next
Next
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 used 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. For example, the abbreviated example below adds a RadProgressBarElement to cell elements in the grid (see Adding Custom Elements to Cells for the full example).
[C#] Handling the CellFormatting Event
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
RadProgressBarElement element = new RadProgressBarElement();
e.CellElement.Children.Add(element);
}
[VB] Handling the CellFormatting Event
Private Sub radGridView1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs)
Dim element As New RadProgressBarElement()
e.CellElement.Children.Add(element)
End Sub
? Dev Components ? RadControls for WinForms ? Telerik Windows Forms RadGridView
Source of Information : 2002-2010 Telerik. All Rights Reserved. Help