By default, sheets display the field names in the column headers when bound to a data set. If you prefer, you can change the text to display custom column names.
Using the Properties Window
- Create your data set.
- In the Properties window, select the Spread component.
- 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.
- If you have not already done so, select the Sheets property for the Spread component.
- Click the button to display the SheetView Collection Editor.
- Click the sheet for which you want to change the column headings.
- If you are providing custom text for every column header, set the DataAutoHeadings property to False so the sheet does not display the field names from the data set as the column header text.
- In the property list, select the Cells property and click the button to display the Cell, Column, and Row Editor.
- Select the column for which you want to change the column headings.
- Set the Label property to the new text you want in the heading.
- Repeat steps 8 and 9 for each column for which you want to set the column heading.
- Click OK to close the Cell, Column, and Row Editor.
- Click OK to close the SheetView Collection Editor.
Using a Shortcut
- Create your data set.
- Set the FpSpread object's or Sheet object's DataSource property equal to the data set.
- If you are providing custom text for every column header, set the Sheet object's DataAutoHeadings property to False so the sheet does not display the field names from the data set as the column header text.
- Set the Text property of the ColumnHeader cells to specify the custom text.
Example
This example code binds the Spread component to a data set then customizes the first column header.
C# |
Copy Code
|
// Bind the component to the data set.
fpSpread1.DataSource = dbDataSet;
// Set custom text in the first column header.
fpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text = "Student ID";
|
VB |
Copy Code
|
' Bind the component to the data set.
fpSpread1.DataSource = dbDataSet
' Set custom text in the first column header.
fpSpread1.Sheets(0).ColumnHeader.Cells(0, 0).Text = "Student ID"
|
Using Code
- Create your data set.
- Create a new SheetView object.
- Set the SheetView object's DataSource property equal to the data set.
- If you are providing custom text for every column header, set the SheetView object's DataAutoHeadings property to False so the sheet does not display the field names from the data set as the column header text.
- Set the Text property for ColumnHeader cells to specify the custom text.
- 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
- Create your data set.
- Set the FpSpread object's or Sheet object's DataSource property equal to the data set.
- Open the Spread Designer for the Spread component.
- Select the sheet tab for the sheet for which you want to set the custom header text.
- If you are providing custom text for every column header, set the DataAutoHeadings property to False so the sheet does not display the field names from the data set as the column header text.
- Select the column for which you want to set custom header text, then right-click and choose Headers.
- In the Header Editor, double-click the header for which you want to display custom text.
- Edit the text to be the custom text you want, and then press Enter to stop editing.
- When you have edited all the header text you want to edit, click OK to close the Header Editor, then click Yes to apply your changes to the selection.
- From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
See Also