Spread Windows Forms 6.0 Product Documentation
GetPreferredWidth Method
See Also  Example Support Options
FarPoint.Win.Spread Assembly > FarPoint.Win.Spread Namespace > Column Class : GetPreferredWidth Method


Glossary Item Box

Gets the minimum width necessary to display all the text within the specified column.

Syntax

Visual Basic (Declaration) 
Public Function GetPreferredWidth() As Single
Visual Basic (Usage)Copy Code
Dim instance As Column
Dim value As Single
 
value = instance.GetPreferredWidth()
C# 
public float GetPreferredWidth()

Return Value

Single-precision, floating-point number of pixels in the width

Remarks

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.

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

Example

This example determines the width of the column based on the text in the first cell.
C#Copy Code
FarPoint.Win.Spread.Column col;
float size;
col = fpSpread1.ActiveSheet.Columns[0];
fpSpread1.ActiveSheet.Cells[0, 0].Text = "This text will be used to determine the width of the column";
size = col.GetPreferredWidth();
col.Width = size;
Visual BasicCopy Code
Dim col As FarPoint.Win.Spread.Column
Dim size As Single
col = FpSpread1.ActiveSheet.Columns(0)
FpSpread1.ActiveSheet.Cells(0, 0).Text = "This text will be used to determine the width of the column"
size = col.GetPreferredWidth()
col.Width = size

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

© 2002-2012 ComponentOne, a division of GrapeCity. All Rights Reserved.