Spread Windows Forms 11.0 Product Documentation
GetPreferredColumnWidth Method


FarPoint.Win.Spread Assembly > FarPoint.Win.Spread Namespace > SheetView Class : 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
Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
Gets the width of the widest cell (based on text content) in the specified column on this sheet.  
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.

See Also

Reference

SheetView Class
SheetView Members
GetPreferredWidth Method

User-Task Documentation

Resizing the Row or Column to Fit the Data