• Understanding FormatConditions [Janus GridEX WinForms Control v3.5 for .NET]

    GridEXFormatCondition class allows developers to specify special format settings for rows or cells in a GridEX control that meet certain criteria.



    At design time, you can add the format conditions in any table using the "GridEX Designer". The steps to add format conditions at design time are as follows:



    1) Right Click in a GridEX control and click at "Grid Designer..." menu . The GridEX designer will appear.



    2) In the GridEX Designer, select the "FormatConditions" node under any of the tables defined in the control.



    3) In the Right panel, Click in the "Add" button to add a new format condition and select the column to be compared (Column property), the comparison to perform (ConditionOperator property) and the Value(s) to compare with it using the Value1/Value2 properties. For instance, to have a special format for rows where the value in the Discontinued field is equal to True, the following properties are set:



    Column = Discontinued

    ConditionOperator = ConditionOperator.Equal

    Value1 = True

    Value2 (Not used. This property is used only when ConditionOperator is Between or NotBetween



    4) Click in the Expand symbol of the FormatStyle property and specify the format settings to be applied in the rows that meet the criteria. For instance, to see rows grayed and with a strike out font set these properties in its FormatStyle:



    ForeColor = SystemColors.GrayText

    FontStrikeout = True



    5) Repeat the add operation until you have finished adding format conditions and click OK in the designer.





    Format conditions can also be created in code. To specify format conditions in code, you create a new GridEXFormatCondition instance specifying the column, the operator and the value(s) that will be compared with the value of that column. After the format condition is created, specify the format settings to use in the rows that meet the criteria using the FormatStyle property and finally add that GridEXFormatCondition to the FormatConditions collection in a table. For example, to highlight products on sale using a font bold use the following code:



    In VB .Net:



    Dim onSaleColumn As GridEXColumn

    'Get a reference of the column to be compared

    onSaleColumn = GridEX1.RootTable.Columns("OnSale")

    'Create the format condition

    Dim fc As GridEXFormatCondition

    fc = New GridEXFormatCondition( onSaleColumn, _

    ConditionOperator.Equal, True)

    ‘Specify the FormatStyle properties you want to be applied in the rows

    ‘where the condition is met.

    fc.FormatStyle.FontBold = TriState.True

    ‘Finally, add the format condition to the table

    GridEX1.RootTable.FormatConditions.Add(fc)





    To apply the FormatStyle of a GridEXFormatCondition in a cell and not in the entire row, you can specify which column to format using the TargetColumn property. For example, to use a red background in cells of the "Balance" column where Balance is less than 0 use the following code:



    Dim column As GridEXColumn

    Dim fc As GridEXFormatCondition

    'get the column to be compared in the condition

    column = GridEX1.RootTable.Columns("Balance")

    'create the condition

    fc = New GridEXFormatCondition(column, _

    ConditionOperator.LessThan, 0)

    fc.FormatStyle.BackColor = Color.Red

    'If TargetColumn is specified, the FormatStyle is applied

    'only to that column

    fc.TargetColumn = column

    'Add the format condition created to the table

    GridEX1.RootTable.FormatConditions.Add(fc)



    Remarks: When a row meets the criteria in two or more conditions, the format settings to be applied in that row are the result of merging the format styles for both conditions. To apply only the format style of the first condition a row meets, set the AllowMerge property in each of the GridEXFormatCondition objects specified as False.

    Source Of Information : Janus v3.5 Help Files for VS 2008


0 comments:

Leave a Reply