Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Data Binding / Customizing Data Binding / Customizing Column Headers for Bound Sheets
In This Topic
    Customizing Column Headers for Bound Sheets
    In This Topic

    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

    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 column headings.
    7. 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.
    8. In the property list, select the Cells property and click the button to display the Cell, Column, and Row Editor.
    9. Select the column for which you want to change the column headings.
    10. Set the Label property to the new text you want in the heading.
    11. Repeat steps 8 and 9 for each column for which you want to set the column heading.
    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 object's or Sheet object's DataSource property equal to the data set.
    3. 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.
    4. 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

    1. Create your data set.
    2. Create a new SheetView object.
    3. Set the SheetView object's DataSource property equal to the data set.
    4. 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.
    5. Set the Text property for 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 object's or Sheet object's 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 custom header text.
    5. 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.
    6. Select the column for which you want to set custom header text, then right-click and choose Headers.
    7. In the Header Editor, double-click the header for which you want to display custom text.
    8. Edit the text to be the custom text you want, and then press Enter to stop editing.
    9. 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.
    10. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
    See Also