Syncfusion - 1 - Auto fill size grid columns.

[ESS, C# 2.0]

Suppose you have a GridBoundDataGrid (gridMain) on a resizable form (Form1). gridMain has three data columns and you want the second to resize so that the full width of the grid is used but no more. How do you do that? Add a resize event to your form and add the following code:

In other words you simply reset the width of the desired column (in this case column 2) to be the grid's client size width (the interior of the of the grid after borders and scroll bars are taken into account) minus the width of all the other columns. The thing to note is that in addition to the three data columns there is also a column 0 which is a header column. By calling the grid's Refresh() method you force a redraw.

You should add a call to Form1_Resize(this, null) after the all the column binding is done to set it initially.


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License