Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Cell Types / Understanding Cell Type Basics
In This Topic
    Understanding Cell Type Basics
    In This Topic

    You can specify the way a user interacts with a cell, including how data is entered, displayed, and validated, by specifying the cell type. The cell type defines an editor control for the cell that handles data entry, a formatter control to handle how the data is interpreted, and a renderer control that handles how the data is displayed in the cell. Examples of cell types are check box cell, date-time cell, or a simple text cell.

    Cell types can be set for individual cells, columns, rows, a range of cells, or an entire sheet. For any cell type there are properties of a cell that can be set. In general, working with cell types includes defining the cell type, setting the properties, and applying that cell type to cells.

    Pay attention to data types when working with cell types. For several cell types, including ComboBoxCellType, DateTimeCellType, and MultipleOptionCellType, there is an EditorValue property. Make sure the Value property you are setting in the cell matches the type specified by the EditorValue property.

    Editor, Formatter, and Renderer

    A cell type consists of an editor, a renderer, and a formatter. The editor is a control instance that is created and placed in the location of the cell when the cell goes into edit mode. The editor is responsible for creating and managing the cell's edit control when in edit mode. The formatter is responsible for converting the cell's value to and from text (for example when getting or setting a cell's Text property). The renderer paints the control inside the cell rectangle when the editor is not there or when the cell is not in edit mode.

    In most cases, you want the cell to look the same whether you are in edit mode or not in edit mode. In these cases, you would create a single cell type and assign it to the cell's CellType property. This single cell type is used as the cell's editor, renderer, and formatter. If you want the cell to appear differently depending on whether you are in edit mode or not in edit mode, then you can create two different cell types and assign one cell type as the cell's editor and the other cell type as the cell's renderer. In this case, you probably also want to assign one of the cell types as the cell's formatter. For more information, refer to the ICellType interface.

    EditBaseCellType

    The design of cell editing requires that the cell type return an editor control that is then placed over the cell. The editor control can be text based (for example, text box) or graphics based (for example, check box). The editor control can drop down lists (for example, combo box) or pop up dialogs (for example, date picker). The EditBaseCellType class is a class from which the built-in text based cell types (for example, general, text, number, data-time, and so on) are derived. The class can also be used to derive custom cell types that are text based. The ISubEditor interface is used to combine a text-based editor with a drop-down list (for example, combo box) or pop-up dialog (for example date picker). The data model can hold any value, including colors. The cell type is always passed the raw value from the data model.

    Header Cells

    While you can assign a cell type to the cells in the row header or column header, the cell type is only used for painting purposes; the component renders header cells but does not allow editing. In‑cell editing is limited to cells in the data area. If you want to have something editable that acts like a header, you can hide (turn off) the column header, freeze the first row of the spreadsheet, then use the frozen row to appear as header cells.

    See Also