'Declaration Public ReadOnly Property CalcValue As Infragistics.Win.CalcEngine.UltraCalcValue
public Infragistics.Win.CalcEngine.UltraCalcValue CalcValue {get;}
CalcValue returns the UltraCalcValue being used by the CalcManager. This is provided so that the programmer can detect special situations like the occurance of a CalculationError.
Imports Infragistics.Shared Imports Infragistics.Win Imports Infragistics.Win.UltraWinGrid Imports Infragistics.Win.CalcEngine Imports Infragistics.Win.UltraWinCalcManager Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Ensure that the form contains an UltraCalcManager and two textboxes, ' one named textBox1 and the other named textBox2. Dim calcSettings As CalcSettings = New CalcSettings() ' This formula will multiply the value of textBox2 by 2. calcSettings.Formula = "2 * [textBox2]" calcSettings.PropertyName = "Text" Me.UltraCalcManager1.SetCalcSettings(Me.TextBox1, calcSettings) calcSettings = New CalcSettings() calcSettings.PropertyName = "Text" ' Treat the values of the textBox2 as double. Text property of TextBox is ' a string type and since textBox2 is a source of value to a formula, indicate ' to the calc-manager that the value should be treated as a double rather ' than as a string. calcSettings.TreatAsType = GetType(Double) Me.UltraCalcManager1.SetCalcSettings(Me.TextBox2, calcSettings) End Sub Private Sub UltraCalcManager1_ParseValue(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinCalcManager.ParseValueEventArgs) Handles ultraCalcManager1.ParseValue ' ParseValue gets fired on all controls that are source of values in formulas. If e.Control Is Me.textBox2 Then ' Get the text of the textBox2. Dim text As String = Me.textBox2.Text If 0 = text.Length Then ' If the textbox is empty, then you can return an error. By default the ' calc manager considers empty strings to be 0. e.Value = New UltraCalcValue(New UltraCalcErrorValue(UltraCalcErrorCode.Num, "Not a Number")) Else ' Otherwise parse the text to a double and return that as the value. ' The calc manager by default uses InvariantCulture to parse text into ' numeric values. Typically you want to use the current culture to parse ' text into numeric values. ParseValue event is especially useful for that. e.Value = New UltraCalcValue(Double.Parse(text)) End If e.Handled = True End If End Sub Private Sub UltraCalcManager1_FormatValue(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinCalcManager.FormatValueEventArgs) Handles ultraCalcManager1.FormatValue ' FormatValue gets fired on all controls that are target of formula evaluations. If e.Control Is Me.textBox1 Then If e.CalcValue.IsError Then ' There was an error in formula evaluation. e.Value = e.CalcValue.ToErrorValue().Message ElseIf e.CalcValue.IsDBNull Or e.CalcValue.IsNull Then ' Result is DBNull or Null. e.Value = "(NULL)" Else Dim doubleVal As Double If e.CalcValue.ToDouble(doubleVal) Then ' ToDouble returns true if the value was a double. e.Value = CType(doubleVal, Decimal).ToString("c") Else ' Otherwise convert the value to a string using current culture. e.Value = e.CalcValue.ToString(System.Globalization.CultureInfo.CurrentCulture) End If End If End If End Sub
using Infragistics.Shared; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; using System.Diagnostics; using Infragistics.Win.CalcEngine; using Infragistics.Win.UltraWinCalcManager; private void Form1_Load(object sender, System.EventArgs e) { // Ensure that the form contains an UltraCalcManager and two textboxes, // one named textBox1 and the other named textBox2. CalcSettings calcSettings = new CalcSettings( ); // This formula will multiply the value of textBox2 by 2. calcSettings.Formula = "2 * [//textBox2]"; calcSettings.PropertyName = "Text"; this.ultraCalcManager1.SetCalcSettings( this.textBox1, calcSettings ); calcSettings = new CalcSettings( ); calcSettings.PropertyName = "Text"; // Treat the values of the textBox2 as double. Text property of TextBox is // a string type and since textBox2 is a source of value to a formula, indicate // to the calc-manager that the value should be treated as a double rather // than as a string. calcSettings.TreatAsType = typeof( double ); this.ultraCalcManager1.SetCalcSettings( this.textBox2, calcSettings ); } private void ultraCalcManager1_ParseValue(object sender, Infragistics.Win.UltraWinCalcManager.ParseValueEventArgs e) { // ParseValue gets fired on all controls that are source of values in formulas. if ( e.Control == this.textBox2 ) { // Get the text of the textBox2. string text = this.textBox2.Text; if ( 0 == text.Length ) { // If the textbox is empty, then you can return an error. By default the // calc manager considers empty strings to be 0. e.Value = new UltraCalcValue( new UltraCalcErrorValue( UltraCalcErrorCode.Num, "Not a Number" ) ); } else { // Otherwise parse the text to a double and return that as the value. // The calc manager by default uses InvariantCulture to parse text into // numeric values. Typically you want to use the current culture to parse // text into numeric values. ParseValue event is especially useful for that. e.Value = new UltraCalcValue( double.Parse( text ) ); } e.Handled = true; } } private void ultraCalcManager1_FormatValue(object sender, Infragistics.Win.UltraWinCalcManager.FormatValueEventArgs e) { // FormatValue gets fired on all controls that are target of formula evaluations. if ( e.Control == this.textBox1 ) { if ( e.CalcValue.IsError ) { // There was an error in formula evaluation. e.Value = e.CalcValue.ToErrorValue( ).Message; } else if ( e.CalcValue.IsDBNull || e.CalcValue.IsNull ) { // Result is DBNull or Null. e.Value = "(NULL)"; } else { double doubleVal; if ( e.CalcValue.ToDouble( out doubleVal ) ) { // ToDouble returns true if the value was a double. e.Value = ((decimal)doubleVal).ToString( "c" ); } else { // Otherwise convert the value to a string using current culture. e.Value = e.CalcValue.ToString( System.Globalization.CultureInfo.CurrentCulture ); } } } }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2