Spread Windows Forms 6.0 Product Documentation
Resizing the Row or Column to Fit the Data
Support Options
Spread Windows Forms 6.0 Product Documentation > Developer's Guide > Customizing Row, Column, and Cell Appearance > Customizing the Row or Column Appearance > Resizing the Row or Column to Fit the Data

Glossary Item Box

You can 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 called the preferred size.

The methods that make use of the preferred size are:

The Row class GetPreferredHeight method and Column class GetPreferredWidth method always include the header cells. The SheetView class overloaded GetPreferredColumnWidth method 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.

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.

Return to Customizing the Row or Column Appearance.

Using Code

Use the various methods to set the width and height of columns or rows.

Example

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
 

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