Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Can you format negative values like Excel?

Can you format negative values like Excel?

New Discussion
Jeff
Jeff asked on Nov 16, 2022 2:23 PM

In Excel, there is an option to format and display negative numbers in parentheses and red (with no negative sign showing) .  Is is possible to format negative numbers in the grid the same way?

I can change the color to red in the InitializeRow even by testing the values and changing the cell appearance.  If I change the number to a string, I can have the parentheses, but then I have to strip out the parens and convert when trying to get the value.

Sign In to post a reply

Replies

  • 0
    Torrey
    Torrey answered on Nov 19, 2008 12:45 AM

    View your UltraGrid Designer and navigate your ways to edit the properties of the columns. Select the column that you'll be formatting the negative numbers. Click into the Format property and paste this into there:

    $#,##0.00;($#,##0.00);Zero

    You can find the formatting references from Microsoft by clicking this link. For the conditional formatting you do not need to use InitializeRow, as we are already in the properties for this column, scroll down to the property called ValueBasedAppearance. With this dialog you can set conditions to change the appearance of the cell based on the value. Don't forget to delete what you had in InitializeRow to save overhead and any conflicting.

    Hope this helps you out!

    • 0
      Jeff
      Jeff answered on Nov 19, 2008 1:02 PM

      Great.  Worked perfectly.  I think I still need to handle InitializeRow to change the ForeColor to Red though.

       

      Thanks for your help.

      • 0
        Torrey
        Torrey answered on Nov 19, 2008 1:28 PM

        I used my junk yard project to toss this video together, so sorry for the sloppiness of it, but you'll see how the conditions work to turn the value foreground to red without using any InitializeRow.

      • 0
        Jeff
        Jeff answered on Nov 19, 2008 3:04 PM

        Awesome video.  Thanks for the extra effort!!!  It was very helpful.

        One question.  In my case I do not define my columns up front.  They are defined when I bind my DataTable since I don't know what columns I will have up front.  Using your example, I created a column in the designer and then followed your steps to create the ConditionValueAppearance.

        In my code, I create a class level variable to hold the ConditionValueAppearance. I I then copied the code that was created in the .Designer file into the Form_Load and assign it to my modular level variable.  In Initialize_Layout, I set the ValueBasedAppearance and the format.  The formatting works, but the ValueBasedAppearance does not seemed to.

        From Form_Load: 

        Dim Appearance1 As New Appearance()

        Appearance1.ForeColor = Color.Red

        _negValueBasedAppearance =

        New Infragistics.Win.ConditionValueAppearance(New Infragistics.Win.ICondition() {CType(New Infragistics.Win.OperatorCondition(Infragistics.Win.ConditionOperator.LessThan, "0", True, GetType(String)), Infragistics.Win.ICondition)}, New Infragistics.Win.Appearance() {Appearance1})

         

        From InializeLayout

        For ii As Integer = 1 To .Columns.Count – 1     Dim col As UltraGridColumn = .Columns(ii)

             col.ValueBasedAppearance = _negValueBasedAppearance

             col.Format =

        "###0.0000;(###0.0000);0.0000"

        Next ii

      • 0
        Torrey
        Torrey answered on Nov 19, 2008 3:49 PM

        Class Level Variables: 

        Dim condition1 As New OperatorCondition(ConditionOperator.LessThan, 0)
        Dim appearance1 as Infragistics.Win.Appearance = New Infragistics.Win.Appearance()
        Dim valAppearance1 As New ConditionValueAppearance()

        From Form_Load:

        appearance1.ForeColor = Color.Red
        valAppearance1.Add(condition1, appearance1)

        Then in your InitializeLayout:

        For ii As Integer = 1 To .Columns.Count – 1     Dim col As UltraGridColumn = .Columns(ii)
             col.ValueBasedAppearance = valAppearance1
             col.Format = "###0.0000;(###0.0000);0.0000"
        Next ii

      • 0
        Jeff
        Jeff answered on Nov 19, 2008 3:57 PM

        That did the trick.  Thanks for your help.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Nov 19, 2008 4:05 PM

        If you are going to be writing code to do this at run-time, anyway, it would be a lot easier and a lot less code to just use the InitializeRow event. 🙂

  • 0
    luna luna
    luna luna answered on Nov 16, 2022 2:23 PM

    Consolidate information with the Ampersand image (and) · Select the cell where you need to put the joined information. · Type = and select the principal cell you need to join. This is how 0 in front of numbers comes along side.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Jeff
Favorites
0
Replies
8
Created On
Nov 16, 2022
Last Post
3 years, 3 months ago

Suggested Discussions

Tags

Created by

Created on

Nov 16, 2022 2:23 PM

Last activity on

Nov 16, 2022 2:23 PM