Spread for WinForms also allows you to resize the column width or row height based on the length or breadth of data in the cells in that column or row. The size of the row or column with the largest data is referred to as the preferred size.
The methods that make use of the preferred size are:
The GetPreferredHeight method of the Row class and GetPreferredWidth method of the Column class always include the header cells. The overloaded GetPreferredColumnWidth method of the SheetView class has one overload that always includes the header cells while another overload allows you to choose whether to include or exclude header cells. In the following code, width1
and width2
include the header cells but width3
excludes the header cells.
C# |
Copy Code
|
---|---|
float width1 = fpspread.Sheets[0].Columns[0].GetPreferredWidth(); float width2 = fpspread.Sheets[0].GetPreferredColumnWidth(0); float width3 = fpspread.Sheets[0].GetPreferredColumnWidth(0, true); |
For information on setting the cell size based on the size of the data, refer to Resizing a Cell to Fit the Data.
For information on allowing the user to resize the data, refer to Allowing the User to Resize Rows or Columns.
C# |
Copy Code
|
---|---|
//Disable WordWrap for all column header labels FarPoint.Win.Spread.CellType.ColumnHeaderRenderer ch = new FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer(); ch.WordWrap = false; fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = ch; |
Visual Basic |
Copy Code
|
---|---|
'Disable WordWrap for all column header labels Dim ch As New FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer ch.WordWrap = False FpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = ch |
This example sets the row height and column width.
C# |
Copy Code
|
---|---|
FarPoint.Win.Spread.Row row; FarPoint.Win.Spread.Column col; float sizerow; float sizercol; row = fpSpread1.ActiveSheet.Rows[0]; col = fpSpread1.ActiveSheet.Columns[0]; fpSpread1.ActiveSheet.Cells[0, 0].Text = "This text is used to determine the height and width."; sizerow = row.GetPreferredHeight(); sizecol = col.GetPreferredWidth(); row.Height = sizerow; col.Width = sizecol; |
VB |
Copy Code
|
---|---|
Dim row As FarPoint.Win.Spread.Row Dim col As FarPoint.Win.Spread.Column Dim sizerow As Single Dim sizecol As Single row = fpSpread1.ActiveSheet.Rows(0) col = fpSpread1.ActiveSheet.Columns(0) fpSpread1.ActiveSheet.Cells(0, 0).Text = "This text is used to determine the height and width." sizerow = row.GetPreferredHeight() sizecol = col.GetPreferredWidth() row.Height = sizerow col.Width = sizecol |