ComponentOne List for WinForms
In This Topic
    Applying Cell Styles by Status
    In This Topic

    Each cell in the List for WinForms display has a status value which identifies its disposition (any combination of current, modified, part of a selected row, or part of a highlighted row). Using the AddCellStyle method, you can set style attributes which apply to any possible combination of cell status values. The AddCellStyle method is supported by the C1List, C1Combo, Split, and C1DisplayColumn objects, enabling you to control the range of cells for which certain conditions apply.

    For each unique status combination, you can set the color, font, and picture attributes to be used for cells of that status. When a cell's status changes, List for WinForms checks to see if any style property overrides are defined for that cell, and applies those attributes to the cell when it is displayed. Style objects are used to specify the color and font for a cell, as in the following example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim S As New C1.Win.C1List.Style()        
    Dim myfont As Font
       
    myfont = New Font(S.Font, FontStyle.Bold)        
    S.Font = myfont        
    S.ForeColor = System.Drawing.Color.Red
       
    Me.C1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S)
    

    To write code in C#

    C#
    Copy Code
    C1.Win.C1List.Style S = new C1.Win.C1List.Style();        
    Font myfont;
    
    myfont = new Font(S.Font, FontStyle.Bold);        
    S.Font = myfont;
            
    S.ForeColor = System.Drawing.Color.Red;  
    this.c1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S);
    

    Here, a new temporary style object is created to specify the color and font (red text, bold) to be applied to the current cell throughout the entire list. Since the style object's BackColor property is not set explicitly, the background color of the current cell is not changed.

    You can also use styles defined at design time as arguments to the AddCellStyle method:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim S As C1.Win.C1List.Style        
    S = Me.C1List1.Styles("RedBold")        
    Me.C1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S)
    

    To write code in C#

    C#
    Copy Code
    C1.Win.C1List.Style S;        
    S = this.c1List1.Styles["RedBold"];       
    this.c1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S);
    

    The preceding example can be simplified since the AddCellStyle method accepts a style name as well as an actual style object:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Me.C1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S)
    

    To write code in C#

    C#
    Copy Code
    this.c1List1.AddCellStyle(C1.Win.C1List.CellStyleFlag.CurrentCell, S);
    

    All of the preceding examples cause the text of the current cell to appear in red and bold. However, it is important to note that the status CurrentCell applies only to cells which have only this status.

    Although this method of specifying cell conditions offers more control and flexibility, it also requires that additional code be written for some common cases.

    Calls to AddCellStyle take effect immediately, and can be used for interactive effects as well as overall list characteristics.