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.
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!
Great. Worked perfectly. I think I still need to handle InitializeRow to change the ForeColor to Red though.
Thanks for your help.
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.
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. :)
That did the trick. Thanks for your help.
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.RedvalAppearance1.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
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.
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
col.ValueBasedAppearance = _negValueBasedAppearance
col.Format = "###0.0000;(###0.0000);0.0000"
Next ii