This sample allows you to display nested tables in a Grid Grouping control without indenting the children of the records in the parent table.
Features:
Can be achieved by hiding the default Record Plus-Minus buttons and having them in the same level as the parent.
Set the TableOptions.ShowIndentTable property of the ChildTableDescriptor to false to hide the default plus-minus buttons.
Handle the QueryCellStyleInfo and TableControlCellClick events to provide the required functionality.
This process is illustrated in the image below.
The QueryCellStyleInfo event is used to format the plus-minus buttons.
The TableControlCellClick event is responsible for expanding and collapsing a record when the plus-minus button is clicked.
The following code is used to turn off the default Record Plus-Minus buttons.
this.gridGroupingControl1.GetTableDescriptor("MyChildTable").TableOptions.ShowTableIndent = false;
The QueryCellStyleInfo event is used to format the plus-minus buttons.
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { if (e.TableCellIdentity.TableCellType == GridTableCellType.NestedTableIndentCell) { if (e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.NestedTable) { // NestedTable GridNestedTable nt = (GridNestedTable)e.TableCellIdentity.DisplayElement; foreach (Element el in nt.ChildTable.Elements) { if (el.Kind == DisplayElementKind.Record) { if (e.TableCellIdentity.RowIndex == this.gridGroupingControl1.Table.NestedDisplayElements.IndexOf(el)) { Record r = Record.GetParentRecord(el); e.TableCellIdentity.TableCellType = GridTableCellType.RecordPlusMinusCell; e.Style.Description = r.IsExpanded ? "-" : "+"; e.Style.BorderMargins = new Syncfusion.Windows.Forms.Grid.GridMarginsInfo(3, 3, 3, 3); e.Style.Themed = false; e.Style.Enabled = true; } } } } } }
The TableControlCellClick event is responsible for expanding and collapsing the record when the Record Plus-Minus button is clicked.
void gridGroupingControl1_TableControlCellButtonClicked(object sender, GridTableControlCellButtonClickedEventArgs e) { GridTableCellStyleInfo style = this.gridGroupingControl1.Table.GetTableCellStyle(e.Inner.RowIndex, e.Inner.ColIndex); if (style.TableCellIdentity.TableCellType == GridTableCellType.RecordPlusMinusCell) { if (style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.NestedTable) { // NestedTable GridNestedTable nt = (GridNestedTable)style.TableCellIdentity.DisplayElement; foreach (Element el in nt.ChildTable.Elements) { if (el.Kind == DisplayElementKind.Record) { if (style.TableCellIdentity.RowIndex == this.gridGroupingControl1.Table.NestedDisplayElements.IndexOf(el)) { Record r = Record.GetParentRecord(el); bool shouldExpand = !r.IsExpanded; this.gridGroupingControl1.Table.CurrentRecord = r; r.IsExpanded = shouldExpand; e.Inner.Cancel = true; } } } } } }