Search code examples
.netnumber-formattingjanus

Janus Grid: Formatting column data meeting a condition


I have a numeric column in a Janus grid. What i want to do is display the numbers in it like (1234) if they are less than zero. I have already managed to change the color of such numbers to red, but i need some help with putting braces around the numbers only if they are less than zero.


Solution

  • The trick here is to set the FormatString of the column.

    The FormatString for numerics is in 3 sections, each separated by a semi colon.

    FormatString for numerics are documented here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

    The section titled 'The ";" Section Separator' covers what you need.

    You can set the Format String in the GridEx designer on the column. The first section is the format for positive numbers, second section for negative numbers and the third section is for formatting zero.

    You don't indicate if decimal places are involved in your scenario, but assuming you need 2 decimal places you can use this as a starting point:

    col.FormatString =  "0.00;(0.00);IsZero"
    

    Taking 3 examples with this FormatString:

    1. 7
    2. -13.4
    3. 0

    would give results

    1. 7.00
    2. (13.40)
    3. IsZero