Table Indent Formatting Demo

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:

NestedTables screenshot



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;
                   }
                 }
             }
       }
   }
}