GrapeCity MultiRow Windows Forms Documentation
ConditionalCellStyle Class
Members  Example 


Represents a special CellStyle that can customize the style using the specified condition. This class cannot be inherited.
Object Model
ConditionalCellStyle ClassConditionalCellStyleItemCollection ClassConditionalCellStyleItem Class
Syntax
<TypeConverterAttribute("GrapeCity.Win.MultiRow.ConditionalCellStyleTypeConverter, GrapeCity.Win.MultiRow, Version=7.20.20141.0, Culture=neutral, PublicKeyToken=0f7a722ee3c2bdd9")>
Public NotInheritable Class ConditionalCellStyle 
   Inherits CellStyle
Dim instance As ConditionalCellStyle
[TypeConverter("GrapeCity.Win.MultiRow.ConditionalCellStyleTypeConverter, GrapeCity.Win.MultiRow, Version=7.20.20141.0, Culture=neutral, PublicKeyToken=0f7a722ee3c2bdd9")]
public sealed class ConditionalCellStyle : CellStyle 
Remarks
The cell can display different styles in different conditions using ConditionalCellStyle. For example, there is a cell that displays a number. You may want the cell to have a "Red" forecolor when the cell value is negative. You can set a ConditionalCellStyle to the cell's Style property. The ConditionalCellStyle should contain a ConditionalCellStyleItem whose ConditionalCellStyleItem.Operator is ConditionalCellStyleOperator.LessThan, whose ConditionalCellStyleItem.Value1 is 0, and whose CellStyle is a "Red" forecolor.
Example
The following code example shows how to implement the conditional cell style. If the value is less than 5, the cell's background is painted green, if the value is between 5 and 8, the background is yellow, if the value is greater than 8, the background is red.
class ConditionalCellStyleDemo : Form
    {
        private GcMultiRow gcMultiRow1 = new GcMultiRow();
        private Label label1 = new Label();

        public ConditionalCellStyleDemo()
        {
            this.Text = "ConditionalCellStyle Demo";
            this.Size = new Size(600, 400);

            this.gcMultiRow1.Dock = DockStyle.Fill;
            this.Controls.Add(this.gcMultiRow1);

            label1.Text = "Change the Cell's value, the corresponding background is painted.\r\nNote, the cells only accept 
int number.";
            label1.Height = 50;
            label1.Dock = DockStyle.Bottom;
            label1.BackColor = SystemColors.Info;
            label1.ForeColor = Color.Red;
            this.Controls.Add(label1);

            this.Load += new EventHandler(Form1_Load);

            this.StartPosition = FormStartPosition.CenterScreen;
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            Template template1 = Template.CreateGridTemplate(10, 50, 21);

            CellStyle cellStyle1 = new CellStyle();
            cellStyle1.BackColor = Color.Lime;

            CellStyle cellStyle2 = new CellStyle();
            cellStyle2.BackColor = Color.Yellow;

            CellStyle cellStyle3 = new CellStyle();
            cellStyle3.BackColor = Color.Red;

            //If the cell's value is less than 5, the background is painted green
            ConditionalCellStyleItem item1 = new ConditionalCellStyleItem(cellStyle1, 
ConditionalCellStyleOperator.LessThan, 5);
            //If the cell's value is between 5 and 8, the background is painted yellow
            ConditionalCellStyleItem item2 = new ConditionalCellStyleItem(cellStyle2, 
ConditionalCellStyleOperator.Between, 5, 8);
            //If the cell's value is greater than 8, the background is painted red
            ConditionalCellStyleItem item3 = new ConditionalCellStyleItem(cellStyle3, 
ConditionalCellStyleOperator.GreaterThan, 8);
            //Create one ConditionalCellStyle with three items.
            ConditionalCellStyle conditionalStyle1 = new ConditionalCellStyle();
            conditionalStyle1.Items.AddRange(new ConditionalCellStyleItem[] { item1, item2, item3 });
            
            for (int i = 0; i < template1.Row.Cells.Count - 1; i++)
            {
                template1.Row.Cells[i].Style = conditionalStyle1;
                template1.Row.Cells[i].Value = i + 1;
                template1.Row.Cells[i].ValueType = typeof(Int32);
            }
            gcMultiRow1.Template = template1;
            gcMultiRow1.RowCount = 5;
        }
Class ConditionalCellStyleDemo
    Inherits Form
    Private gcMultiRow1 As New GcMultiRow()
    Private label1 As New Label()

    Public Sub New()
        Me.Text = "ConditionalCellStyle Demo"
        Me.Size = New Size(600, 400)

        Me.gcMultiRow1.Dock = DockStyle.Fill
        Me.Controls.Add(Me.gcMultiRow1)

        label1.Text = "Change the Cell's value, the corresponding background will be painted. \r\nNote, the cells only 
accept int number."
        label1.Height = 50
        label1.Dock = DockStyle.Bottom
        label1.BackColor = SystemColors.Info
        label1.ForeColor = Color.Red
        Me.Controls.Add(label1)

        Me.StartPosition = FormStartPosition.CenterScreen
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim template1 As Template = Template.CreateGridTemplate(10, 50, 21)

        Dim cellStyle1 As New CellStyle()
        cellStyle1.BackColor = Color.Lime

        Dim cellStyle2 As New CellStyle()
        cellStyle2.BackColor = Color.Yellow

        Dim cellStyle3 As New CellStyle()
        cellStyle3.BackColor = Color.Red

        'If the cell's value is less than 5, the background is painted green
        Dim item1 As New ConditionalCellStyleItem(cellStyle1, ConditionalCellStyleOperator.LessThan, 5)
        'If the cell's value is between 5 and 8, the background is painted yellow
        Dim item2 As New ConditionalCellStyleItem(cellStyle2, ConditionalCellStyleOperator.Between, 5, 8)
        'If the cell's value is greater than 8, the background is painted red 
        Dim item3 As New ConditionalCellStyleItem(cellStyle3, ConditionalCellStyleOperator.GreaterThan, 8)
        'Create one ConditionalCellStyle with three items.
        Dim conditionalStyle1 As New ConditionalCellStyle()
        conditionalStyle1.Items.AddRange(New ConditionalCellStyleItem() {item1, item2, item3})

        For i As Integer = 0 To template1.Row.Cells.Count - 2
            template1.Row.Cells(i).Style = conditionalStyle1
            template1.Row.Cells(i).Value = i + 1
            template1.Row.Cells(i).ValueType = GetType(Int32)
        Next

        gcMultiRow1.Template = template1
        gcMultiRow1.RowCount = 5
    End Sub
Inheritance Hierarchy

System.Object
   GrapeCity.Win.MultiRow.CellStyle
      GrapeCity.Win.MultiRow.ConditionalCellStyle

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

ConditionalCellStyle Members
GrapeCity.Win.MultiRow Namespace
CellStyle Class
DynamicCellStyle Class
NamedCellStyle Class
CombinedCellStyle Class
ConditionalCellStyleItemCollection Class

 

 


Copyright © GrapeCity, inc. All rights reserved.