FlexGrid for WinForms
CellStyle Class
Members  Example 



The CellStyle class encapsulates properties that control the appearance of grid cells. This information includes the background and foreground colors, font, text and image alignment, etc.
Object Model
CellStyle ClassCellBorder Class
Syntax
'Declaration
 
<TypeConverterAttribute("System.ComponentModel.ExpandableObjectConverter, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")>
<RefreshPropertiesAttribute(RefreshProperties.Repaint)>
<EditorAttribute(EditorBaseTypeName="System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", EditorTypeName="C1.Win.C1FlexGrid.Design.StyleUITypeEditor, C1.Win.C1FlexGrid.4.Design")>
Public Class CellStyle 
'Usage
 
Dim instance As CellStyle
[TypeConverter("System.ComponentModel.ExpandableObjectConverter, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[RefreshProperties(RefreshProperties.Repaint)]
[Editor(EditorBaseTypeName="System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", EditorTypeName="C1.Win.C1FlexGrid.Design.StyleUITypeEditor, C1.Win.C1FlexGrid.4.Design")]
public class CellStyle 
[TypeConverter("System.ComponentModel.ExpandableObjectConverter, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[RefreshProperties(RefreshProperties.Repaint)]
[Editor(EditorBaseTypeName="System.Drawing.Design.UITypeEditor, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", EditorTypeName="C1.Win.C1FlexGrid.Design.StyleUITypeEditor, C1.Win.C1FlexGrid.4.Design")]
public ref class CellStyle 
Remarks

The C1FlexGridBase.Styles property exposes a collection of grid styles, and has methods for creating and removing styles from the grid.

You can create and define styles at design time, but right-clicking the grid and selecting the "Edit Styles" menu option.

Styles follow a hierarchical model similar to styles in Microsoft Word or in cascading style sheets. Every property in a CellStyle object may be left unassigned, in which case the value is inherited from a parent style. The parent style is usually the built-in CellStyleCollection.Normal style.

To determine which elements are defined in a particular style, use the DefinedElements property.

When you modify the properties of a CellStyle object, all cells that use that style are automatically repainted to reflect the changes.

Styles may be assigned to CellRange, Row, and Column objects, as shown in the example below.

Example
The example below creates three CellStyle objects and assigns them to grid rows, columns, and cell ranges.

After running this code, the third column of the grid will be painted with a red background. The third row will be painted with a green background. The cell at the intersection will be painted in red, because column styles have priority over row styles. The remaining style elements for these cells (font, alignment, etc) are not defined in the new styles and are automatically inherited from the parent style (CellStyleCollection.Normal).

The cells around the intersection will have a bold font. The style that defines the bold font does not specify a background color, so that element is inherited from the parent style, which may be the "red", "green", or "normal" styles.

// create style with red background
CellStyle cs = _flex.Styles.Add("red");
Style.BackColor = Color.Red;
            
// create style with green background
cs = _flex.Styles.Add("green");
Style.BackColor = Color.Green;
            
// create style with bold font
cs = _flex.Styles.Add("bold");
Style.Font = new Font("Tahoma", 8, FontStyle.Bold);
            
// assign red style to a column
_flex.Cols[3].Style = _flex.Styles["red"];
            
// assign green style to a row
_flex.Rows[3].Style = _flex.Styles["green"];
            
// assign bold style to a cell range
CellRange rg = _flex.GetCellRange(2, 2, 4, 4);
rg.Style = _flex.Styles["bold"];
Inheritance Hierarchy

System.Object
   C1.Win.C1FlexGrid.CellStyle

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CellStyle Members
C1.Win.C1FlexGrid Namespace

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Send Feedback