Articles in this section
Category / Section

How to resize the last column to client size of the grid in WinForms GridControl?

1 min read

Resize the last column

To resize the last column to client size of the Grid, you can use the QueryColWidth event. This customizes the width of the column.

C#

this.gridControl1.Model.QueryColWidth += Model_QueryColWidth;         
void Model_QueryColWidth(object sender, Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs e)
{
    if (e.Index > this.gridControl1.ColCount - 1)
    {
        //Resizes the last column to client size.
        this.Col_size = this.gridControl1.Model.ColWidths.GetTotal(0, this.gridControl1.ColCount - 1);
        e.Size = this.gridControl1.ClientSize.Width - Col_size;
        e.Handled = true;
    }  
}         

VB

Private Me.gridControl1.Model.QueryColWidth += AddressOf Model_QueryColWidth
Private Sub Model_QueryColWidth(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs)
  If e.Index > Me.gridControl1.ColCount - 1 Then
    'Resizes the last column to client size.
    Me.Col_size = Me.gridControl1.Model.ColWidths.GetTotal(0, Me.gridControl1.ColCount - 1)
      e.Size = Me.gridControl1.ClientSize.Width - Col_size
      e.Handled = True
  End If
End Sub

 

The screenshot displays the Grid after applying the properties:

Resizing the last column in gridcontrol

Samples:

C#: Resize Column

VB: Resize Column

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment