Articles in this section
Category / Section

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

2 mins read

Resize the last column


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

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;
    }  
}
AddHandler 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


Conclusion

I hope you enjoyed learning about how to resize the last column to the client size of the grid in WinForms GridControl.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

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