I am attempting to use an UltraCalcManager to get a SUM() of a few columns from different UltraGrids. However, instead of placing the result in a column, I'd like to place it in the .Text of a label. So far, it seems to do the math properly.
There is one little caveat: How do I format the result as currency? In the UltraGrid, we can do {0:C2} for a summary column. I do not see any properties that I can set on the UltraCalcManager.
Do I need to handle a particular UltraCalcManager event?
Thanks,Kyle
Mike,
Your answer put me on the right track! Luckily, my labels are just the target. However, there was a little change I had to make. For the CalcManager properties of the Label, I had to set the PropertyName from Text to Tag.
Here's the code that does simply what we want:
Private Sub uclcMgr_FormatValue(ByVal sender As System.Object, ByVal e As UltraWinCalcManager.FormatValueEventArgs) Handles uclcMgr.FormatValue If TypeOf e.Control Is System.Windows.Forms.Label Then CType(e.Control, Label).Text = Convert.ToDecimal(e.Value).ToString("C2") End IfEnd Sub
Hi Kyle,
You can use the FormatValue event of the WinCalcManager to format the value as currency.
However, you have to be a little bit careful. The WinGrid cell has the ability to store one value and display another. So you can store a value and display it formatted and there's no problem when the CalcManage asks for the Value of the cell, because the format just changes the display and not the value.
A Label doesn't have this capability. So the FormatValue event will change the value that is being applied to the Text property of the label. If the label is only being used as the target (result) of a formula, then this is no problem. But if you are also using this label as the source value in some other formula, then you will also need to handle the ParseValue event to un-format the string into a numeric value that the CalcManager can use.