How to resize the last column to client size of the grid in WinForms GridControl?
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 in WinForms GridControl.
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:
Conclusion
I hope you enjoyed learning about how to set AutoEllipsis mode when text exceeds width of the cell.
You can refer to our Winsform GridControl feature grid.page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
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!