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.
Unfortunately, activation email could not send to your email. Please try again.

How do I resize the column widths proportionately when the grid is resized in the virtual grid?

Solution

Method 1: Using the built-in property

Set the AllowProportionalColumnSizing to True, to auto-resize the columns when the grid is resized.

C#

VB

Way 2: Using work-around

To auto-size the columns, you can use grid.ColWidths.ResieToFit and create an array of doubles. For example, in this array, colRatios, computes the ratio of each column width to the grid.ClientSize.Width.

This gives the proper proportion value for each column. Then you can subscribe to grid.QueryColWidth and provide the size of the column widths by multiplying this ratio with the grid's width. Set e.Handled = true. You can refer to the following codes.

C#

VB

Sample Link

C#: ColumnResizeInGC

VB: ColumnResizeInGC

Article ID: Published Date: Last Revised Date: Platform: Control:
431 04/30/2011 04/21/2015 Windows Forms GridControl
Did you find this information helpful?
Comments
Sergii Golik Dec 19, 2014
You have 3 types of grids, how to adjust width for all of them ?
Reply
Muthukumar Kalyanasundaram [Syncfusion] Dec 20, 2014
Hi Sergii, Thank you for your interest in Syncfusion products. If you want to adjust the width of the column in a grid. Please make use of below suggestion. GridControl Suggestion 1: If you want to set the width of column in a grid, you can use the “DefaultColWidth” properties. Please refer the below link, Link: http://help.syncfusion.com/ug/windows%20forms/default.htm#!documents/settingcolumnwidthsa.htm Suggestion 2: If you want to change the width for specific column in a grid, you can use the “ColWidths” properties. Please refer the below code, Code: this.grid.ColWidths[2] = 150; Me.grid.ColWidths[2] = 150 (or) this.grid.ColWidths["Col2"] = 150; Me.grid.ColWidths["Col2"] = 200; GridDataBoundGrid Control Suggestion 1: If you want to set the width of column in a grid, you can use the “DefaultColWidth” properties. Please refer the below code, Code: this.grid.DefaultColWidth = 150; Me.grid.DefaultColWidth = 150 Suggestion 2: If you want to change the width for specific column in a grid, you can use the “ColWidths” properties. Please refer the below code, Code: this.grid.Model.ColWidths[2] = 150; Me.grid.Model.ColWidths[2] = 150 (or) this.grid.Model.ColWidths["Col2"] = 150 Me.grid.Model.ColWidths["Col2"] = 200; Note: Please ensure that you can set the “AllowResizeToFit” properties as false. Code: this.grid.AllowResizeToFit = False; Me.grid.AllowResizeToFit = False GridGroupingControl Suggestion 1: If you want to set the width of column in a grid, you can use the “DefaultColWidth” properties. Please refer the below code, Code: this.gridGroupingControl1.TableControl.DefaultColWidth = 130; Me.gridGroupingControl1.TableControl.DefaultColWidth = 130 Suggestion 2: If you want to change the width for specific column in a grid, you can use the “ColWidths” properties. Please refer the below code, Code: this.gridGroupingControl1.TableModel.ColWidths[2] = 130; Me.gridGroupingControl1.TableModel.ColWidths[2] = 130 (or) this.gridGroupingControl1.TableModel.ColWidths[“Col2”] = 130; Me.gridGroupingControl1.TableModel.ColWidths[“Col2”] = 130 Note: Please ensure that if you already set the “ResizeToFit” property for column, the width of the column is not set. Please let us know if you have any concern. Regards, Muthukumar K
Muthukumar Kalyanasundaram [Syncfusion] Dec 20, 2014
Hi Sergii, Thank you for your interest in Syncfusion products. If you want to adjust the width of the column in a grid. Please make use of below suggestion. Grid Control:- Suggestion -1: If you want to set the width of column in a grid, you can use the “DefaultColWidth” properties. Please refer the below link, Link: http://help.syncfusion.com/ug/windows%20forms/default.htm#!documents/settingcolumnwidthsa.htm Suggestion -2: If you want to change the width for specific column in a grid, you can use the “ColWidths” properties. Please refer the below code, Code: this.grid.ColWidths[2] = 150; Me.grid.ColWidths[2] = 150 (or) this.grid.ColWidths["Col2"] = 150; Me.grid.ColWidths["Col2"] = 150 GridDataBoundGrid Control:- Suggestion 1: To set width for all the column in a grid. Code: this.grid.DefaultColWidth = 150; Me.grid.DefaultColWidth = 150 Suggestion 2: To set width for specific Column in a grid. Code: this.grid.Model.ColWidths[2] = 150; Me.grid.Model.ColWidths[2] = 150 (or) this.grid.Model.ColWidths["Col2"] = 150; Me.grid.Model.ColWidths["Col2"] = 150 Note: Please ensure that you can set the “AllowResizeToFit” properties as false Code: this.grid.AllowResizeToFit = False; Me.grid.AllowResizeToFit = False GridGroupingControl:- Suggestion 1: To set width for all the column in a grid. Code: this.gridGroupingControl1.TableControl.DefaultColWidth = 130; Me.gridGroupingControl1.TableControl.DefaultColWidth = 130 Suggestion2: Toet width for specific Column in a grid. Code: this.gridGroupingControl1.TableModel.ColWidths[2] = 130; Me.gridGroupingControl1.TableModel.ColWidths[2] = 130 (or) this.gridGroupingControl1.TableModel.ColWidths[“Col2”] = 130; Me.gridGroupingControl1.TableModel.ColWidths[“Col2”] = 130 Note:- Please ensure that if you already set the “ResizeToFit” property for column in a grid, the width of the column is not set (above all suggestion are not working) Please let us know if you have any concern. Regards, Muthukumar K
Add Comment
You must log in to leave a comment

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.