Spread Windows Forms 10.0 Product Documentation
GetPreferredColumnWidth Method


Gets the width of the widest cell (based on text content) in the specified column on this sheet.
Gets the width of the widest text string in the specified column on the sheet.
Overload List
OverloadDescription
GetPreferredColumnWidth(Int32)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
GetPreferredColumnWidth(Int32,Boolean)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
GetPreferredColumnWidth(Int32,Boolean,Boolean)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
GetPreferredColumnWidth(Int32,Boolean,Boolean,Boolean)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
GetPreferredColumnWidth(Int32,Boolean,Boolean,Boolean,Boolean)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
GetPreferredColumnWidth(Int32,PreferredSizeColumnOptions)Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
Remarks

Column widths can be based on the data in the cells using this method or the Column.GetPreferredWidth method. For more information, see Resizing the Row and Column to Fit the Data.

These methods return the optimal width for a column based on the data it contains. It loops through each cell in the column and calls the GetPreferredSize method on the IRenderer interface for the composite StyleInfo.Renderer for the cell in the style model and returns the maximum value.

If you have set up the cells to format the text with multiple lines (GeneralCellType with WordWrap equal to true, or TextCellType with Multiline or WordWrap or both equal to true), then the GetPreferredSize method returns the optimal width to show all of the text in the cell with the current column width. For text cells or header cells with text, be sure that you turn off word wrapping by setting the WordWrap property for that text cell or header cell to false.

If you have very many columns, then you might want to create a custom axis model for SheetView.DocumentModels.ColumnAxis to return this value. All that should require is creating a class derived from DefaultSheetAxisModel that takes a reference to the SheetView in its constructor and stores it in a field and overrides the GetSize method to call this method for the column index.

In other words, this loops through each cell and calls GetPreferredSize on each cell's composite style's renderer and returns the maximum width for all cells in the column. Refer to GetPreferredSize to find the more detailed explanation of how that works with multiple-line versus single-line text.

For more information on how a composite style works, refer to ISheetStyleModel.GetCompositeInfo.

Requirements

Target Platforms: Windows 2000 Professional (SP4), Windows 2000 Server, Windows 2003 Server (SP1), Windows Server 2012 R2, Windows 2008, Windows XP (SP2), Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10

See Also

Reference

SheetView Class
SheetView Members
GetPreferredWidth Method

User-Task Documentation

Resizing the Row or Column to Fit the Data

 

 


Copyright © GrapeCity, inc. All rights reserved.