GrapeCity MultiRow Windows Forms Documentation
Displaying Negative Values in Red (NumericUpDownCell)

You can display negative values in red using conditional cell styles.

Using the Designer

  1. Select the numeric up down cell to display negative values in (for example: numericUpDownCell1).
  2. Select the Style property from the Properties window and then select Combined Style from the drop-down.

  3. Click the arrow to the left of the Style property to expand the members of CombinedClass and then click the Items property collection button [...].
  4. Add the cell style in the CombinedCellStyle editor and set the following cell style settings.
    • Set the ForeColor property to Black
    • Set the TextAlign property to TopRight
  5. Add the conditional cell style and use the following settings for the Items property of the ConditionalCellStyle property.
    1. Click the [...] button of the Items property collection.
    2. Add Is less than from the Conditional Formatting Rules Editor.

    3. Select Number from the condition cell value.

    4. With the CellStyle selected in CellStyle type, set the ForeColor property to Red.

  6. Click the OK button and verify the changes.
  7. Switch the document window tab to Runtime.
  8. Check the difference in display when values -1,0, and 1 are entered (verify the results by moving the focus to another other cell because string color does not change while the cell is selected).

Using Code

This example displays negative cell values when using conditional cell styles.

[VB]

Imports GrapeCity.Win.MultiRow

Dim numericUpDownCell1 As New NumericUpDownCell()
numericUpDownCell1.Name = "numericUpDownCell1"
numericUpDownCell1.Value = 0

Dim baseStyle As New CellStyle()
baseStyle.ForeColor = Color.Black
baseStyle.TextAlign = MultiRowContentAlignment.TopRight

Dim negativeValueColor As New CellStyle()
negativeValueColor.ForeColor = Color.Red
Dim conditionalCellStyle1 As New ConditionalCellStyle()
conditionalCellStyle1.Items.Add(negativeValueColor, ConditionalCellStyleOperator.LessThan, 0)

Dim combinedCellStyle1 As New CombinedCellStyle()
combinedCellStyle1.Items.Add(baseStyle)
combinedCellStyle1.Items.Add(conditionalCellStyle1)

numericUpDownCell1.Style = combinedCellStyle1

GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {numericUpDownCell1})

[CS]

using GrapeCity.Win.MultiRow;

NumericUpDownCell numericUpDownCell1 = new NumericUpDownCell();
numericUpDownCell1.Name = "numericUpDownCell1";
numericUpDownCell1.Value = 0;

CellStyle baseStyle = new CellStyle();
baseStyle.ForeColor = Color.Black;
baseStyle.TextAlign = MultiRowContentAlignment.TopRight;

CellStyle negativeValueColor = new CellStyle();
negativeValueColor.ForeColor = Color.Red;
ConditionalCellStyle conditionalCellStyle1 = new ConditionalCellStyle();
conditionalCellStyle1.Items.Add(negativeValueColor, ConditionalCellStyleOperator.LessThan, 0);

CombinedCellStyle combinedCellStyle1 = new CombinedCellStyle();
combinedCellStyle1.Items.Add(baseStyle);
combinedCellStyle1.Items.Add(conditionalCellStyle1);

numericUpDownCell1.Style = combinedCellStyle1;

gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { numericUpDownCell1 });
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options