We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
close icon
Learn why digital business metrics are essential to beating your business goals.
Syncfusion Feedback

How to display nested tables in the same level as the parent without being indented in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: March 2, 2015 |
Last Revised Date: February 13, 2020

Display nested table in same level

The child table can be displayed in the same level as the parent by hiding the default RecordPlusMinus buttons. To hide the +/- buttons, the TableOptions.ShowIndentTable property of the ChildTableDescriptor should be set to false. Then, the QueryCellStyleInfo and TableControlCellButtonClicked events have to be handled in a proper way to get this working. The following codes show how to achieve this.

Step 1: Setting the TableOptions.ShowIndent property.

C#

//Sets ShowTableIndent to false for the ChildTable.
this.gridGroupingControl1.GetTableDescriptor("ChildTable").TableOptions.ShowTableIndent = false;

VB

'Sets ShowTableIndent to false for the ChildTable.
Me.gridGroupingControl1.GetTableDescriptor("ChildTable").TableOptions.ShowTableIndent = False

Step 2: Handling the QueryCellStyleInfo event to format the PlusMinus buttons.

C#

this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo;    
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.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;
                }
            }
         }
      }
   }
}

VB

Private Me.gridGroupingControl1.QueryCellStyleInfo += AddressOf gridGroupingControl1_QueryCellStyleInfo
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
   If e.TableCellIdentity.TableCellType = GridTableCellType.NestedTableIndentCell Then
      If e.TableCellIdentity.DisplayElement.Kind = DisplayElementKind.NestedTable Then
         'NestedTable.
         Dim nt As GridNestedTable = CType(e.TableCellIdentity.DisplayElement, GridNestedTable)
         For Each el As Element In nt.ChildTable.Elements
            If el.Kind Is DisplayElementKind.Record Then
     If e.TableCellIdentity.RowIndex = Me.gridGroupingControl1.Table.NestedDisplayElements.IndexOf(el) Then
        Dim r As Record = Record.GetParentRecord(el)
        e.TableCellIdentity.TableCellType = GridTableCellType.RecordPlusMinusCell
        e.Style.Description = If(r.IsExpanded, "-", "+")
        e.Style.BorderMargins = New Syncfusion.Windows.Forms.Grid.GridMarginsInfo(3, 3, 3, 3)
        e.Style.Themed = False
        e.Style.Enabled = True
     End If
  End If
         Next el
      End If
   End If
End Sub

Step 3: The TableControlCellButtonClicked event is responsible for expanding/collapsing the record when its RecordPlusMinus button is pressed.

C#

this.gridGroupingControl1.TableControlCellButtonClicked += gridGroupingControl1_TableControlCellButtonClicked;          
//Expands the Records on the plus/Minus button Click.
void gridGroupingControl1_TableControlCellButtonClicked(object sender, GridTableControlCellButtonClickedEventArgs e)
{
   GridTableCellStyleInfo style = this.gridGroupingControl1.Table.GetTableCellStyle(e.Inner.RowIndex, e.Inner.ColIndex);
   if(style.TableCellIdentity == null)
      return;
   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;
               }
            }
         }
      }
   }
}

VB

Private Me.gridGroupingControl1.TableControlCellButtonClicked += AddressOf gridGroupingControl1_TableControlCellButtonClicked
'Expands the Records on the plus/Minus button Click.
Private Sub gridGroupingControl1_TableControlCellButtonClicked(ByVal sender As Object, ByVal e As GridTableControlCellButtonClickedEventArgs)
   Dim style As GridTableCellStyleInfo = Me.gridGroupingControl1.Table.GetTableCellStyle(e.Inner.RowIndex, e.Inner.ColIndex)
   If style.TableCellIdentity Is Nothing Then
      Return
   End If
   If style.TableCellIdentity.TableCellType = GridTableCellType.RecordPlusMinusCell Then
      If style.TableCellIdentity.DisplayElement.Kind = DisplayElementKind.NestedTable Then
         'NestedTable.
         Dim nt As GridNestedTable = CType(style.TableCellIdentity.DisplayElement, GridNestedTable)
         For Each el As Element In nt.ChildTable.Elements
   If el.Kind Is DisplayElementKind.Record Then
      If style.TableCellIdentity.RowIndex = Me.gridGroupingControl1.Table.NestedDisplayElements.IndexOf(el) Then
         Dim r As Record = Record.GetParentRecord(el)
         Dim shouldExpand As Boolean = Not r.IsExpanded
         Me.gridGroupingControl1.Table.CurrentRecord = r
         r.IsExpanded = shouldExpand
         e.Inner.Cancel = True
      End If
   End If
         Next el
      End If
   End If
End Sub

Show the nested table in the same level

Figure 1: The Nested Table in the same level

Samples:

C#: DisplayNestedTableInSameLevel-C#1694527386.zip

VB: DisplayNestedTableInSameLevel-VB2052906042.zip

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon