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