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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to auto extend a column to fill the available space in the WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl

Handle QueryColWidth event

To dynamically change the column widths, you have to handle the Grid's QueryColWidth event. The following example shows how you can have the right-most or the left-most column grow to fill the Grid's client area as the Grid size changes.


//Defines the columns to fill the space in the table.
void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
   switch (_colSizeBehavior)
       case colSizeBehavior.RightColumn:
               if(e.Index == this.gridGroupingControl1.TableDescriptor.VisibleColumns.Count)
                  e.Size = this.gridGroupingControl1.ClientSize.Width - this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0,
                  this.gridGroupingControl1.TableDescriptor.VisibleColumns.Count - 1);
                  e.Handled = true;
       case colSizeBehavior.LeftColumn:
               if(e.Index == this.gridGroupingControl1.TableModel.Cols.FrozenCount + 1)
                  int leftPiece = this.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, this.gridGroupingControl1.TableModel.Cols.FrozenCount);
                  int rightPiece = this.gridGroupingControl1.TableModel.ColWidths.GetTotal(this.gridGroupingControl1.TableModel.Cols.FrozenCount + 2, this.gridGroupingControl1.TableModel.ColCount);
                  e.Size = this.gridGroupingControl1.ClientSize.Width - leftPiece - rightPiece;
                  e.Handled = true;


'Defines the columns to fill the space in the table.
Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
   Select Case _colSizeBehavior
       Case colSizeBehavior.RightColumn
                If e.Index = Me.gridGroupingControl1.TableDescriptor.VisibleColumns.Count Then
                   e.Size = Me.gridGroupingControl1.ClientSize.Width - Me.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, Me.gridGroupingControl1.TableDescriptor.VisibleColumns.Count - 1)
                   e.Handled = True
                End If
       Case colSizeBehavior.LeftColumn
                If e.Index = Me.gridGroupingControl1.TableModel.Cols.FrozenCount + 1 Then
                   Dim leftPiece As Integer = Me.gridGroupingControl1.TableModel.ColWidths.GetTotal(0, Me.gridGroupingControl1.TableModel.Cols.FrozenCount)
                   Dim rightPiece As Integer = Me.gridGroupingControl1.TableModel.ColWidths.GetTotal(Me.gridGroupingControl1.TableModel.Cols.FrozenCount + 2, Me.gridGroupingControl1.TableModel.ColCount)
                   e.Size = Me.gridGroupingControl1.ClientSize.Width - leftPiece - rightPiece
                   e.Handled = True
                End If
       Case Else
   End Select
End Sub

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

Left column to fill the available space in Grid

Figure 1: The left column to fill the available space


C#: Auto extending column

VB: Auto extending column

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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