$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView WinForms Component
Bind GridView C#.NET control to hierarchical data in Windows Forms applications
Home > WinForms UI Controls > User Manual > Expand Rows in C#

GridView Hierarchical Child Rows and Cells Customizing

When we bind the GridView component to hierarchical data, we may customize the child rows and cells. The Kettic GridView control allows users customize the child rows of hierarchical data. In this article, we are going to talk about how to access the child templates, how to expand all rows including parent and child rows, how to iterate the child rows collection of a chosen parent row in hierarchy GridView and how to create formatting cells in a child template.

How to Access Child Templates in C#.NET

The Kettic GridView provides the GridView.MasterTemplate.ChildTemplates templates collection for users to access to the child templates. The following C# code demonstrates how to customize the AutoSizeColumnsMode property to Fill in the first child template to GridView.

this.ketticGridView1.MasterTemplate.Templates[0].AutoSizeColumnsMode = Kettic.WinForms.UI.GridViewAutoSizeColumnsMode.Fill;

How to Expand Hierarchical Rows in C#.NET

The Kettic GridView allows users to expand all hierarchical rows including parent and child rows, and then iterate through the rows and change the value of the IsExpanded property to true. The following are the C# code that shows how to expand all child rows of Kettic GridView.

void ExpandAllRows(GridViewTemplate template, bool expanded)
{
foreach (GridViewRowInfo row in template.Rows)
{
row.IsExpanded = true;
}
if (template.Templates.Count > 0)
{
foreach (GridViewTemplate childTemplate in template.Templates)
{
ExpandAllRows(childTemplate, true);
}
}
}

How to Iterate Child Rows in C#.NET

The Kettic GridView provides the support of iterating the child rows collections. This is achieved by using the grid template GetChildRows metod. The following are the C# code that shows how to iterate the child rows collection of a chosen parent row in hierarchy GridView.

private void IterateChildRows(GridViewRowInformation rowInformation)
{
bool expandedState = rowInfo.IsExpanded;
rowInfo.IsExpanded = true;

GridViewRowInformation [] childRows = rowInformation.ChildRows.ToArray<GridViewRowInformation>();

for (int i = 0; i < childRows.Length; i++)
{
Console.WriteLine(childRows[i].Cells[0].Value);
}

rowInfo.IsExpanded = expandedState;

this.ketticGridView1.TableElement.Update(GridUINotifyAction.Reset);
}

How to Create Formatting Cells in C#.NET

The Kettic GridView allows users to create formatting cells in GridView. The following are the C# code that shows how to change the back color of the grid cells in the child.

void ketticGridView1_FormatViewCell (object sender, FormatCellEventArgs e)
{
if (e.CellElement.ViewTemplate.Parent != null)
{
e.CellElement.BackColor = Color.Green;
e.CellElement.NumberOfColors = 1;
e.CellElement.DrawFill = true;
}
}
One more example is to change the header row height of the child template. The C# code below demonstrates how to change the header height of the first level child template.

void ketticGridView1_FormatCellView(object sender, FormatCellEventArgs e)
{
if (e.CellElement.ViewTemplate.Parent != null)
{
e.CellElement.TableElement.TableHeaderHeight = 80;
}
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls