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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Progamatically setting column width in GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

8739 Nov 18,2003 12:09 PM UTC Nov 18,2003 03:35 PM UTC WinForms 3
loading
Tags: GridControl
Jeff Block
Asked On November 18, 2003 12:09 PM UTC

I am attempting to initialize a grid programtically, hiding columns, setting header text, etc. All seems to be going well, except that setting the column width seems to have no affect. I am setting 3 columns with the following code, as well as displaying the column width before and after setting: Debug.WriteLine( string.Format( "ColumnName: {0}, width before setting is {1}.", dataset.Orders.OrderNumberColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OrderNumberColumn.ColumnName ] )); orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OrderNumberColumn.ColumnName ] = 70; Debug.WriteLine( string.Format( "ColumnName: {0}, width after setting is {1}.", dataset.Orders.OrderNumberColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OrderNumberColumn.ColumnName ] )); Debug.WriteLine( string.Format( "ColumnName: {0}, width before setting is {1}.", dataset.Orders.ReleaseColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.ReleaseColumn.ColumnName ] )); orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.ReleaseColumn.ColumnName ] = 40; Debug.WriteLine( string.Format( "ColumnName: {0}, width after settting is {1}.", dataset.Orders.ReleaseColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.ReleaseColumn.ColumnName ] )); Debug.WriteLine( string.Format( "ColumnName: {0}, width before setting is {1}.", dataset.Orders.OPNColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OPNColumn.ColumnName ] )); orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OPNColumn.ColumnName ] = 200; Debug.WriteLine( string.Format( "ColumnName: {0}, width after setting is {1}.", dataset.Orders.OPNColumn.ColumnName, orderSelection.SelectionGrid.Model.ColWidths[ dataset.Orders.OPNColumn.ColumnName ] )); The grid always comes up with the same "look"! Is there a property somewhere that needs turned off or something to honor specifically setting the column widths? Jeff

Jeff Block
Replied On November 18, 2003 12:12 PM UTC

By the way, the Debug statements show: ColumnName: OrderNumber, width before setting is 65. ColumnName: OrderNumber, width after setting is 70. ColumnName: Release, width before setting is 65. ColumnName: Release, width after settting is 40. ColumnName: OPN, width before setting is 65. ColumnName: OPN, width after setting is 200. which is what I would expect... Jeff

Administrator [Syncfusion]
Replied On November 18, 2003 03:26 PM UTC

Make sure grid.AllowResizeToFit is set to false. If it is not, then the grid autosizes the columns based on header text which might be stepping on your changes.

Jeff Block
Replied On November 18, 2003 03:35 PM UTC

That was the missing piece, works beautifully now, thanks! Jeff

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon 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.Close Icon

;