Spread Windows Forms 18
Spread Windows Forms 18 Product Documentation / Developer's Guide / Understanding the Underlying Models / Understanding the Sheet Model Classes and Interfaces / Understanding the Style Model
In This Topic
    Understanding the Style Model
    In This Topic

    The style model includes appearance settings which might be:

    For more information on appearance settings for a sheet, refer to Creating a Custom Skin for a Sheet and Applying a Skin to a Sheet. For more information on appearance settings for a cell, refer to Creating and Applying a Style for Cells.

    More information about the style model is provided in the following topics:

    The style model includes the cell types as well. The various cell types determine the appearance of a cell in several ways. For more information about the various cell types, refer to Cell Types.

    Refer to the DefaultSheetStyleModel class for more information on the style model in general and the methods in particular.

    For more details, refer to the BaseSheetStyleModel class, the DefaultSheetStyleModel class, and the ISheetStyleModel interface.

    Settings and Objects for Style

    The appearance settings may be set from any of the following classes in the FarPoint Spread namespace that represent shortcut objects:

    They can also be set from any of these classes in the FarPoint Spread namespace that affect style:

    Properties that correspond to StyleInfo properties are stored in the style model through the ISheetStyleModel interface. Style properties can be set for a cell, row (column index -1), column (row index -1), or the entire model (column and row index -1). Properties that are not set in a cell are inherited from the row setting, or the column setting if the row has no setting, or the model default if the column also has no setting.

    The default is exposed through the DefaultStyle property (SheetView.DefaultStyle, ColumnHeader.DefaultStyle, and RowHeader.DefaultStyle). If you set or get a style property using Rows.Default or Rows[-1] or Columns.Default or Columns[-1], then you will actually be setting or getting the DefaultStyle property. This is because Column and Row always use row index -1 and column index -1 when accessing the style model, respectively, and so using a column index or a row index of -1 will be setting or getting the model default.

    Order of Inheritance of Styles

    The order of inheritance is described in Object Parentage. Here is a list of the style properties that are included in the style model, which are basically the members of the StyleInfo class and affect the appearance or style of a cell:

    Composited or Inherited Styles

    The style properties for a cell can be composited or merged from the Cell, Row, Column, SheetView, and parent NamedStyle objects.

    To use the underlying style model, use the methods of the style model for that sheet, specifically the GetDirectInfo method and SetDirectInfo method, and the settings in the StyleInfo object. "Direct" in the style model means "not composite" or "not inherited." SetDirectInfo sets the style properties that have been set for the specified cell, column, or row directly and does not return any settings that are set for higher levels (such as the entire model), while GetCompositeInfo gives the style properties "composed" or "merged" into one StyleInfo object that contains all the settings that are used to paint and edit the cell, column, or row, including any inherited settings.

    Style Name

    Setting StyleName replaces the style in the style model with the NamedStyle having the specified name. Replacing the style with the NamedStyle changes the settings of all of the style-related properties, including ParentStyleName (which wraps StyleInfo.Parent). Any previous setting for style-related properties like BackColor, Font, Border, or ParentStyleName are overwritten when you set StyleName. All of these properties are already set in the NamedStyle object; the component’s properties are not changed just because you assigned the NamedStyle to a cell, column, row or alternating row. The named style is expected to already be set up the way you want it to be. If this includes the named style having a parent NamedStyle, then you should have that parent set already when you assign it with StyleName, or you should assign it separately using a reference to the NamedStyle object (this has the same effect as setting ParentStyleName after setting StyleName).

    Keep in mind that after you have set StyleName, all cells where you have used that name are sharing the same NamedStyle object, and any changes that you make to one of those cells will also change all of the other cells sharing the same named style.

    The following code creates two NamedStyle objects with a parent-child relationship, then sets some properties on the styles and adds them to the NamedStyleCollection in the Spread component.

    C#
    Copy Code
    NamedStyle test_parent = new NamedStyle("test_parent");
    test_parent.BackColor = Color.Red;
    test.ForeColor = Color.White;
    fpSpread1.NamedStyles.AddRange(new NamedStyle[] {test_parent, test});
    fpSpread1.Sheets(0).Columns(0).BackColor = Color.Blue;
    fpSpread1.Sheets(0).Rows(0).CellType = new NumberCellType();
    fpSpread1.Sheets(0).Cells(0,0).StyleName = "test";
    fpSpread1.Sheets(0).Cells(1,0).StyleName = "test";
    
    VB
    Copy Code
    Dim test_parent As NamedStyle = New NamedStyle("test_parent")
    test_parent.BackColor = Color.Red
    test.ForeColor = Color.White
    fpSpread1.NamedStyles.AddRange(New NamedStyle() {test_parent, test})
    fpSpread1.Sheets[0].Columns[0].BackColor = Color.Blue
    fpSpread1.Sheets[0].Rows[0].CellType = New NumberCellType()
    fpSpread1.Sheets[0].Cells[0,0].StyleName = "test"
    fpSpread1.Sheets[0].Cells[1,0].StyleName = "test"
    

    In the example, the background color for the first column is set to blue and the cell type for the first row is set to Number, and the first cells in the first two rows are both set to use the NamedStyle named "test." The result is that the cells in the first column are blue, except for the cells in the first two rows, which are red because the "test" style inherits the red background color from its parent NamedStyle. The parent style overrides the inherited setting for the column.

    The cell type for the first cell is Number, since there is cell type set in either NamedStyle object. There is a cell type set in the first row which is inherited by all cells in the row. The cell type for the second cell is General since there is no cell type setting for the cell, row, or column. The default cell type for the sheet is General. For more information on inheritance of style settings, refer to Object Parentage.

    Format Objects

    The FormatInfo strings in a saved XML file are DateTimeFormatInfo or NumberFormatInfo objects that store the format of the data. These are created in the style model when a General cell is edited, if the style model implements IParseFormatSupport. These format objects allow the cells to display the data in the same format that was used to enter it.

    The General cell type parses the string into a number or DateTime, and generates the IFormatProvider and format string necessary to render the data as it was entered. If you use TextCellType instead of GeneralCellType, then it works the same as the Edit cells did in the ActiveX FarPoint Spread, and no FormatInfo is stored in the style model, but the data entered into the cells is always treated as text.

    See Also