)
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.
Syncfusion Feedback

How to allocate equal size for each of the columns in all the tables of the WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 30, 2011 |
Last Revised Date: February 12, 2020

Allocate equal size for each column

The parent or child table’s column width can be set equally in proportion to the grid client’s width by dynamically setting the column’s width in the TableModel.QueryColWidth event handler. When it deals with a nested table, the QueryColWidth event of the entire nested table must be handled to set the respective nested table’s column width.

C#

void TableModel_QueryColWidth(object sender, Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs e)
{
    //Allows editing,grouping,filtering operations.
    GridTableModel gridModel = sender as GridTableModel;
    GridTableControl grid = (GridTableControl)gridModel.ActiveGridView;
    if (gridModel != null && grid != null)
    {               
        if (VScrollVisible)
            //Gets the information about vertical scrollbar.
            VSBarSize = SystemInformation.VerticalScrollBarWidth;
            indentCols = (gridModel.GetColumnIndentCount()) * grid.GroupingControl.TableOptions.IndentWidth;
            //Checks whether the table is a parent table or not.
            if (grid.TableDescriptor.Name == "ParentTable")
            {
                if (e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1)
                {
                    parentIndentCols = VScrollVisible ? indentCols : indentCols - SystemInformation.VerticalScrollBarWidth;
                    availableArea = grid.GroupingControl.ClientSize.Width - indentCols - VSBarSize;
                    e.Size = (int)availableArea / (grid.TableDescriptor.VisibleColumns.Count);
                    e.Handled = true;
                }
            }
           //Checks whether the table is a child table or not.
           if (grid.TableDescriptor.Name == "ChildTable")
           {
               if (e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1)
               {
                   childIndentCols = indentCols;
                   availableArea = grid.GroupingControl.ClientSize.Width - gridModel.ColWidths.GetTotal(0, gridModel.Cols.HeaderCount) - indentCols - parentIndentCols;
                   e.Size = (int)availableArea / (grid.TableDescriptor.VisibleColumns.Count);
                   e.Handled = true;
               }
          }
          //Checks whether the table is a grandchildtable or not.
          if (grid.TableDescriptor.Name == "GrandChildTable")
          {
              if (e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1)
              {
                  availableArea = grid.GroupingControl.ClientSize.Width - gridModel.ColWidths.GetTotal(0, gridModel.Cols.HeaderCount) - indentCols - parentIndentCols - childIndentCols;
                  e.Size = (int)availableArea / (grid.TableDescriptor.VisibleColumns.Count);
                  e.Handled = true;
              }
          }              
    }
}      

VB

Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs)
    'Allows editing,grouping,filtering operations.
    Dim gridModel As GridTableModel = TryCast(sender, GridTableModel)
    Dim grid As GridTableControl = CType(gridModel.ActiveGridView, GridTableControl)
    If gridModel IsNot Nothing AndAlso grid IsNot Nothing Then
        If VScrollVisible Then
            'Gets the information about vertical scrollbar.
   VSBarSize = SystemInformation.VerticalScrollBarWidth
        End If
        indentCols = (gridModel.GetColumnIndentCount()) * grid.GroupingControl.TableOptions.IndentWidth
        'Checks whether the table is a parent table or not.
         If grid.TableDescriptor.Name = "ParentTable" Then
             If e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1 Then
                parentIndentCols = If(VScrollVisible, indentCols, indentCols - SystemInformation.VerticalScrollBarWidth)
                availableArea = grid.GroupingControl.ClientSize.Width - indentCols - VSBarSize
                e.Size = CInt(Fix(availableArea)) / (grid.TableDescriptor.VisibleColumns.Count)
      e.Handled = True
          End If
      End If
      'Checks whether the table is a child table or not.
      If grid.TableDescriptor.Name = "ChildTable" Then
          If e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1 Then
              childIndentCols = indentCols
              availableArea = grid.GroupingControl.ClientSize.Width - gridModel.ColWidths.GetTotal(0, gridModel.Cols.HeaderCount) - indentCols - parentIndentCols
              e.Size = CInt(Fix(availableArea)) / (grid.TableDescriptor.VisibleColumns.Count)
              e.Handled = True
          End If
      End If
      'Checks whether the table is a grandchildtable or not.
      If grid.TableDescriptor.Name = "GrandChildTable" Then
          If e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1 Then
              availableArea = grid.GroupingControl.ClientSize.Width - gridModel.ColWidths.GetTotal(0, gridModel.Cols.HeaderCount) - indentCols - parentIndentCols - childIndentCols
              e.Size = CInt(Fix(availableArea)) / (grid.TableDescriptor.VisibleColumns.Count)
              e.Handled = True
          End If
      End If
   End If
End Sub

After applying the properties, the grid looks like the following screenshot.

Show equal size allocated to all the columns in all the tables

Figure 1: Equal size allocated to all the columns in all the tables

Samples:

C#: Allocating equal size for columns

VB: Allocating equal size for columns

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