Spread Windows Forms 9.0 Product Documentation > Developer's Guide > Managing Data Binding > Customizing Data Binding > Customizing Cell Types for Bound Sheets |
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.
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 |
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 |