Spread Windows Forms 6.0 Product Documentation
Customizing Cell Types for Bound Sheets
Support Options
Spread Windows Forms 6.0 Product Documentation > Developer's Guide > Managing Data Binding > Customizing Data Binding > Customizing Cell Types for Bound Sheets

Glossary Item Box

By default, when the Spread component or sheet is bound to a data set, it sets the cell types for the bound rows based on the data in the data set. You can turn off this automatic cell type assignment and assign cell types yourself.

Return to the overall list of tasks in Customizing Data Binding.

Using the Properties Window

  1. Create your data set.
  2. In the Properties window, select the Spread component.
  3. Select the DataSource property (for the Spread component) or select the Sheets property and set the DataSource property, and set it equal to the data set.
  4. If you have not already done so, select the Sheets property for the Spread component.
  5. Click the button to display the SheetView Collection Editor.
  6. Click the sheet for which you want to change the cell types.
  7. Set the DataAutoCellTypes property to False so the sheet does not automatically assign the cell types for the columns.
  8. In the property list, select the Columns property and click the button to display the Cell, Column, and Row Editor.
  9. Select the column for which you want to change the cell type.
  10. Set the CellType property to the cell type you want to use for the column.
  11. Repeat steps 8 and 9 for each column for which you want to set the cell type.
  12. Click OK to close the Cell, Column, and Row Editor.
  13. Click OK to close the SheetView Collection Editor.

Using a Shortcut

  1. Create your data set.
  2. Set the FpSpread or Sheet DataSource property equal to the data set.
  3. Set the Sheet’s DataAutoCellTypes property to False so the sheet does not automatically assign the cell types for the columns.
  4. Set the Columns’ CellType property to specify the cell type for each column.

Example

This example code binds the Spread component to a data set then assigns the cell types for its three columns.

C# Copy Code
// Bind the component to the data set.
 
fpSpread1.DataSource = dbDataSet;
 
// Turn off automatic cell type assignment.
 
fpSpread1.Sheets[0].DataAutoCellTypes = false;
 
// Set the first column as general cell type.
 
FarPoint.Win.Spread.CellType.GeneralCellType generalct = new FarPoint.Win.Spread.CellType.GeneralCellType();
 
fpSpread1.Sheets[0].Columns[0].CellType = generalct;
 
// Set the second column as number cell type.
 
FarPoint.Win.Spread.CellType.NumberCellType numberct = new FarPoint.Win.Spread.CellType.NumberCellType();
 
fpSpread1.Sheets[0].Columns[1].CellType = numberct;
 
// Set the third column as currency cell type.
 
FarPoint.Win.Spread.CellType.CurrencyCellType currct = new FarPoint.Win.Spread.CellType.CurrencyCellType();
 
fpSpread1.Sheets[0].Columns[2].CellType = currct;
 
VB Copy Code
' Bind the component to the data set.
 
FpSpread1.DataSource = dbDataSet
 
' Turn off automatic cell type assignment.
 
FpSpread1.Sheets(0).DataAutoCellTypes = False
 
' Set the first column as general cell type.
 
Dim generalct As New FarPoint.Win.Spread.CellType.GeneralCellType()
 
FpSpread1.Sheets(0).Columns(0).CellType = generalct
 
' Set the second column as number cell type.
 
Dim numberct As New FarPoint.Win.Spread.CellType.NumberCellType()
 
FpSpread1.Sheets(0).Columns(1).CellType = numberct
 
' Set the third column as currency cell type.
 
Dim currct As New FarPoint.Win.Spread.CellType.CurrencyCellType()
 
FpSpread1.Sheets(0).Columns(2).CellType = currct
 

Using Code

  1. Create your data set.
  2. Create a new SheetView object.
  3. Set the SheetView object DataSource property equal to the data set.
  4. If you are providing custom text for every column header, set the SheetView object DataAutoHeadings property to False so the sheet does not display the field names from the data set as the column header text.
  5. Set the Text property of the ColumnHeader Cells to specify the custom text.
  6. Assign the SheetView object to a sheet in the component.

Example

This example code creates a bound SheetView object and customizes the text in the first column header cell, then assigns it to a sheet in a Spread component.

C# Copy Code
// Create a new SheetView object.
 
FarPoint.Win.Spread.SheetView newsheet = new FarPoint.Win.Spread.SheetView();
 
// Bind the SheetView object to the data set.
 
newsheet.DataSource = dataSet1;
 
// Change the column header text in the first header cell.
 
newsheet.ColumnHeader.Cells[0, 0].Text = "Student ID";
 
// Assign the SheetView object to the first sheet.
 
fpSpread1.Sheets[0] = newsheet;
 
VB Copy Code
' Create a new SheetView object.
 
Dim newsheet As New FarPoint.Win.Spread.SheetView()
 
' Bind the SheetView object to the data set.
 
newsheet.DataSource = DataSet1
 
' Change the column header text in the first header cell.
 
newsheet.ColumnHeader.Cells(0, 0).Text = "Student ID"
 
' Assign the SheetView object to the first sheet.
 
FpSpread1.Sheets(0) = newsheet
 

Using the Spread Designer

  1. Create your data set.
  2. Set the FpSpread or Sheet DataSource property equal to the data set.
  3. Open the Spread Designer for the Spread component.
  4. Select the sheet tab for the sheet for which you want to set the cell types.
  5. Set the DataAutoCellTypes property to False so the sheet does not automatically assign the cell types for the columns.
  6. Select the column for which you want to set the cell type.
  7. In the property list, set the CellType property to the cell type you want to use for the column.
  8. Repeat steps 6 and 7 for each column for which you want to set the cell type.
  9. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
© 2002-2012 ComponentOne, a division of GrapeCity. All Rights Reserved.