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
JB
Jeff Block
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
AD
Administrator
Syncfusion Team
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.
JB
Jeff Block
November 18, 2003 03:35 PM UTC
That was the missing piece, works beautifully now, thanks!
Jeff