Essential Grid’s Grid Grouping Control supports hierarchical data sets.
Features:
In this sample, you will see five levels of relations being represented with each level having its own nested table. When a user changes the foreign-key value of a record in a nested table, the Grid Grouping Control will automatically move the record to its new parent table and scroll the table into view.
This image shows how the sample looks after execution.
Implementation
The following code describes the creation of the summary column descriptor and how to add it to the table.
//Creating a new SummaryColumnDescriptor.
GridSummaryColumnDescriptor countCat = new GridSummaryColumnDescriptor("RecordCount");
//Setting it's properties.
countCat.SummaryType = SummaryType.Count;
countCat.Style = GridSummaryStyle.FillRow;
//Initializing it to the Column it is associated with.
countCat.DataMember = "CategoryID";
//Mentioning the format of display.
countCat.Format = " {Count} Records.";
//Adding the SummaryColumnDescriptor to the SummaryRowDescriptor.
GridSummaryRowDescriptor categoriesSummaryRow = new GridSummaryRowDescriptor("RecordCountRow");
categoriesSummaryRow.SummaryColumns.Add(countCat);
//Adding the SummaryRowDescriptor to the TableDesriptor.
categoriesTableDescriptor.SummaryRows.Add(categoriesSummaryRow);
//Pick a record with the value "Spegesild" and set it as current record.
r.SetCurrent();
// Expand records and nested tables.
r.IsExpanded = true;
r.NestedTables[0].IsExpanded = true;
Record orderDetailsRecords = r.NestedTables[0].ChildTable.GetFirstRecord();
// Expand the Group the record belongs to.
orderDetailsRecords.ParentGroup.IsExpanded = true;
// Scrolls this record in view.
groupingGrid1.TableControl.ScrollInView(orderDetailsRecords);
//Mention the ColumnIndex to be present at the left-most side of the Grid.
groupingGrid1.TableControl.LeftColIndex = 1;
//Code to disable and enable XP themes.
this.groupingGrid1.ThemesEnabled = true ;
//Code to mention the current position of the scrollbar at the scrollbar control.
groupingGrid1.TableControl.VScrollBar.Value = groupingGrid1.TableControl.VScrollBar.Minimum;
//Code to get the current element, expand and reset the current element.
// Determine current element. If it is a nested table, get the current element of the child table
Element el = this.groupingGrid1.Table.CurrentElement;
while (el is NestedTable)
el = ((NestedTable) el).ChildTable.ParentTable.CurrentElement;
// Expand all records.
this.groupingGrid1.Table.ExpandAllRecords();
// Scroll current record into view.
if (el != null)
{
// Restore Current Field
el.ParentTable.CurrentRecordManager.NavigateTo(el);
// Scroll element into view.
groupingGrid1.TableControl.ScrollInView(el);
}
// Synchronize grid display with engine changes.
this.groupingGrid1.Update();
//Code to collapse all the records.
this.groupingGrid1.Table.CollapseAllRecords();