)
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 auto extend a column to fill the available space in the WinForms GridGroupingControl?

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

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.

C#

//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;
               }
               break;
       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;
               }
               break;
       default:
               break;
    }
}

VB

'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

Figure 1: The left column to fill the available space

Samples:

C#: Auto extending column

VB: Auto extending column

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