$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView for Windows Forms
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > Rows and Child Rows in C#

Rows and Child Rows of C# DataGridView

The Kettic DataGridView control provides the collections, Rows and Child Rows, to include data rows. The Rows collections include all data rows of the Kettic GridView control and the operations of selecting, grouping, sorting, filtering, and scrolling, will not change the content or order in which the grid rows objects exist. The ChildRows collection will returns the data rows stands for the Kettic GridView in the order appearing. The operations of grouping, sorting, filtering will change the ChildRows collection each time.

Sample of Rows and ChildRows

We are going through the example below to understand the difference between Rows and ChildRows. In the example below, there is a Kettic DataGridView that has been bound to the data source table. We will add a column representing the indices of the rows of the Rows collection and a column representing the indices of the rows in the context of the ChildRows collection to the GridView. And then execute some data operations, grouping, sorting, and filtering, to shows how the ChildRows collection will be changed.
1. Add two columns to the GirdView control for C# Windows Forms application

GridViewTextBoxColumn rowsIDColumn = new GridViewTextBoxColumn();
rowsIDColumn.HeaderText = "Rows IDs";
rowsIDColumn.Name = "RowsIDs";
this.ketticGridView1.Columns.Add(rowsIDColumn);

GridViewTextBoxColumn childRowsIDColumn = new GridViewTextBoxColumn();
childRowsIDColumn.HeaderText = "ChildRows IDs";
childRowsIDColumn.Name = "ChildRowsIDs";
this.ketticGridView1.Columns.Add(childRowsIDColumn);
2. Fill integers to the two columns according to the rows order in the collections of Rows and the ChildRows. In this step, we will not apply any operations like grouping, sorting, and filtering, so the ChildRows of the GridView will not change anything.

private void ketticButton1_Click(object sender, EventArgs e)
{
SetIDs();
}

private void SetIDs()
{
for (int i = 0; i < this.ketticGridView1.Rows.Count; i++)
{
this.ketticGridView1.Rows[i].Cells["RowsIDs"].Value = i.ToString();
}

for (int i = 0; i < this.ketticGridView1.ChildRows.Count; i++)
{
this.ketticGridView1.ChildRows[i].Cells["ChildRowsIDs"].Value = i.ToString();
}
}

3. In this step, we will perform the data operation to check the changes of the ChildRows. For instance, we can apply the filtering to the Kettic GridView. When the filtering data operation occurs, the FilterChanged event is fired, and in the event handler of the FilterChanged event, the indices will be refilled the two columns. Finally, the indices of the grid rows will not match anymore.
4. In this step, we will perform the sorting data operation to the records from the above step to the column. The SortChanged event is fired and the two custom columns will be refilled by the indices. The result is expected and the rows in the ChildRows are the only rows shown by the GridView and ordered as representing.

void ketticGridView1_SortChanged(object sender, Kettic.WinForms.UI.GridViewCollectionChangedEventArgs e)
{
SetIDs();
}

5. Finally, we will perform the grouping data operation to the City column. We will fire the GroupChanged event, in which the event handler will be filled by indices to the two columns.

void ketticGridView1_GroupByChanged(object sender, GridViewCollectionChangedEventArgs e)
{
SetIDs();
}
The above C# code has not finished the grouping. Furthermore, we need to modify the body of the SetIDs method as following C# code to get the correct and expected result.
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