GrapeCity MultiRow Windows Forms Documentation
ErrorInfo Property
Example 


Gets or sets error information that is displayed when an exception occurs during the calculation.
Syntax
Public Property ErrorInfo As String
Dim instance As CalculationContext
Dim value As String
 
instance.ErrorInfo = value
 
value = instance.ErrorInfo
public string ErrorInfo {get; set;}

Property Value

A System.String value that represents the error information. The default is a null reference (Nothing in Visual Basic).
Example
The following code example shows how to customize the summary cell's calculation logic. This code example is part of a larger example provided for the SummaryCell class.
private SummaryCell CreateCustomSummaryCell()
        {
            SummaryCell summaryCell = new SummaryCell();
            // Custom calculation logic.
            summaryCell.Calculation = new PercentageCalculation();
            summaryCell.Style.Format = "#0.00%";
            summaryCell.Style.BackColor = Color.Wheat;
            return summaryCell;
        }

        class PercentageCalculation : ICalculation
        {
            public object Calculate(CalculationContext context)
            {
                // calculate the percentage based on current section's subtotal in total.
                object subTotalValue = context.GcMultiRow[context.SectionIndex, "SubTotal"].Value;
                object totalValue = context.GcMultiRow.ColumnFooters[0]["Total"].Value;

                if (object.Equals(totalValue, 0m))
                {
                    // context.ErrorInfo = "Total is 0.";
                    return "Total is 0";
                }

                return (decimal)subTotalValue / (decimal)totalValue;
            }

            public object Clone()
            {
                // If a new property is in the calculation, clone the property with this method.
                return new PercentageCalculation();
            }
        }
Private Function CreateCustomSummaryCell() As SummaryCell
        Dim summaryCell As New SummaryCell()
        ' Custom calculation logic.
        summaryCell.Calculation = New PercentageCalculation()
        summaryCell.Style.Format = "#0.00%"
        summaryCell.Style.BackColor = Color.Wheat
        Return summaryCell
    End Function

    Private Class PercentageCalculation
        Implements ICalculation
        Public Function Calculate(ByVal context As CalculationContext) As Object Implements 
ICalculation.Calculate
            ' calculate the percentage based on current section's subtotal in total.
            Dim subTotalValue As Object = context.GcMultiRow(context.SectionIndex, "SubTotal").Value
            Dim totalValue As Object = context.GcMultiRow.ColumnFooters(0)("Total").Value

            If Object.Equals(totalValue, 0D) Then
                ' context.ErrorInfo = "Total is 0.";
                Return "Total is 0"
            End If

            Return DirectCast(subTotalValue, Decimal) / DirectCast(totalValue, Decimal)
        End Function

        Public Function Clone() As Object Implements ICloneable.Clone
            ' If a new property is in the calculation, make sure the property is cloned in this method.
            Return New PercentageCalculation()
        End Function
    End Class
Requirements

Target Platforms: 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

Reference

CalculationContext Class
CalculationContext Members

 

 


Copyright © GrapeCity, inc. All rights reserved.