Version

ConvertFromUltraCalcValue Method

Converts the result of a formula to a value that will be assigned to the object with the formula.
Syntax
'Declaration
 
Function ConvertFromUltraCalcValue( _
   ByVal calcValue As UltraCalcValue, _
   ByVal context As Object _
) As Object
object ConvertFromUltraCalcValue( 
   UltraCalcValue calcValue,
   object context
)

Parameters

calcValue
Formula result.
context
This is the object with the formula. For example, a cell or a summary.
Example
Following code demonstrates the concepts behind IFormulaValueConverter interface. It implements this interface and assigns it to a column and a summary in the InitializeLayout event handler. The summary has a formula that uses the column as the source.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid
Imports Infragistics.Win.CalcEngine


    Class CustomFormulaValueConverter
        Implements IFormulaValueConverter

        Private Function ConvertFromUltraCalcValue(ByVal formulaResult As UltraCalcValue, ByVal context As Object) As Object Implements IFormulaValueConverter.ConvertFromUltraCalcValue
            ' ConvertFromUltraCalcValue gets called by the UltraWinGrid whenever a
            ' formula is evaluated. You typically use this method to convert the formula
            ' result which may be in one type or format to the type and format of the
            ' column. NOTE: The calc engine uses invariant culture to parse and format
            ' values.

            System.Diagnostics.Debug.WriteLine("ConvertFromUltraCalcValue called:")

            ' Context parameter is the object that's the target of the formula
            ' evaluation. It's either an UltraGridCell or SummaryValue instance in the
            ' case of UltraWinGrid.
            System.Diagnostics.Debug.WriteLine("     TypeOf Context is " & context.GetType().Name)

            If formulaResult.IsError Then
                ' Handle situations where the result of the formula evaluation is error.
                System.Diagnostics.Debug.WriteLine("     Formula TypeOf result is error: " & formulaResult.ToString())

                ' Return the value you want to assigned to the cell or the summary.
                Return "#E"
            Else
                System.Diagnostics.Debug.WriteLine("     Formula evaluated to: " & formulaResult.ToString())

                ' Return the value you want to assigned to the cell or the summary. 
                ' Typically you return a value that's the same type as the column's data type.
                Return formulaResult.ToDecimal()
            End If
        End Function

        Private Function ConvertToUltraCalcValue(ByVal cellValue As Object, ByVal context As Object) As UltraCalcValue Implements IFormulaValueConverter.ConvertToUltraCalcValue
            ' ConvertToUltraCalcValue gets called by the UltraWinGrid whenever a cell or
            ' summary value is fed to a formula during evaluation. You typically use this
            ' method to convert the cell values which may be in one format (for example
            ' the US culture format) to the format that's appropriate for the formula
            ' evaluation. NOTE: The calc engine uses invariant culture to parse and
            ' format values.

            System.Diagnostics.Debug.WriteLine("ConvertToUltraCalcValue called:")

            ' Context parameter is the object associated with the cell value. It's either
            ' an UltraGridCell or SummaryValue instance in the case of UltraWinGrid
            ' objects however it could be UltraCalcSettings or NamedReference instances
            ' as well if the formula refers to a control outside of the grid or a named
            ' reference.
            System.Diagnostics.Debug.WriteLine("     TypeOf Context is " & context.GetType().Name)

            If Nothing Is cellValue Or DBNull.Value Is cellValue Then
                System.Diagnostics.Debug.WriteLine("     Value being TypeOf converted is (NULL)")
                Return New UltraCalcValue(cellValue)
            End If

            System.Diagnostics.Debug.WriteLine("     Value being TypeOf converted is " & cellValue.ToString())
            Dim val As Double = Double.Parse(cellValue.ToString())
            Return New UltraCalcValue(val)
        End Function

    End Class

    Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles ultraGrid1.InitializeLayout
        Dim column As UltraGridColumn = Me.ultraGrid1.DisplayLayout.Bands(0).Columns(0)

        ' Add a summary that calculates the total of the column.
        Dim summary As SummarySettings = column.Band.Summaries.Add("sum( [" & column.Key & "] )")

        ' Set the FormulaValueConverter on both the column and summary.
        column.FormulaValueConverter = New CustomFormulaValueConverter()
        summary.FormulaValueConverter = New CustomFormulaValueConverter()
    End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;
using Infragistics.Win.CalcEngine;


		private class CustomFormulaValueConverter : IFormulaValueConverter
		{
			public object ConvertFromUltraCalcValue( UltraCalcValue formulaResult, object context )
			{
				// ConvertFromUltraCalcValue gets called by the UltraWinGrid whenever a
				// formula is evaluated. You typically use this method to convert the formula
				// result which may be in one type or format to the type and format of the
				// column. NOTE: The calc engine uses invariant culture to parse and format
				// values.

				System.Diagnostics.Debug.WriteLine( "ConvertFromUltraCalcValue called:" );

				// Context parameter is the object that's the target of the formula
				// evaluation. It's either an UltraGridCell or SummaryValue instance in the
				// case of UltraWinGrid.
				System.Diagnostics.Debug.WriteLine( "     Context is " + context.GetType( ).Name );

				if ( formulaResult.IsError )
				{
					// Handle situations where the result of the formula evaluation is error.
					System.Diagnostics.Debug.WriteLine( "     Formula result is error: " + formulaResult.ToString( ) );

					// Return the value you want to assigned to the cell or the summary.
					return "#E";
				}
				else
				{
					System.Diagnostics.Debug.WriteLine( "     Formula evaluated to: " + formulaResult.ToString( ) );

					// Return the value you want to assigned to the cell or the summary. 
					// Typically you return a value that's the same type as the column's data type.
					return formulaResult.ToDecimal( );
				}
			}

			public UltraCalcValue ConvertToUltraCalcValue( object cellValue, object context )
			{
				// ConvertToUltraCalcValue gets called by the UltraWinGrid whenever a cell or
				// summary value is fed to a formula during evaluation. You typically use this
				// method to convert the cell values which may be in one format (for example
				// the US culture format) to the format that's appropriate for the formula
				// evaluation. NOTE: The calc engine uses invariant culture to parse and
				// format values.

				System.Diagnostics.Debug.WriteLine( "ConvertToUltraCalcValue called:" );

				// Context parameter is the object associated with the cell value. It's either
				// an UltraGridCell or SummaryValue instance in the case of UltraWinGrid
				// objects however it could be UltraCalcSettings or NamedReference instances
				// as well if the formula refers to a control outside of the grid or a named
				// reference.
				System.Diagnostics.Debug.WriteLine( "     Context is " + context.GetType( ).Name );

				if ( null == cellValue || DBNull.Value == cellValue )
				{
					System.Diagnostics.Debug.WriteLine( "     Value being converted is (NULL)" );
					return new UltraCalcValue( cellValue );
				}

				System.Diagnostics.Debug.WriteLine( "     Value being converted is " + cellValue.ToString( ) );
				double val = double.Parse( cellValue.ToString( ) );
				return new UltraCalcValue( val );
			}
		}

		private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
		{
			UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns[0];

			// Add a summary that calculates the total of the column.
			SummarySettings summary = column.Band.Summaries.Add( "sum( [" + column.Key + "] )" );

			// Set the FormulaValueConverter on both the column and summary.
			column.FormulaValueConverter = new CustomFormulaValueConverter( );
			summary.FormulaValueConverter = new CustomFormulaValueConverter( );
		}
Requirements

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

See Also