Custom value class and SUM

Posted by: kbj on 2 May 2019, 11:31 pm EST

  • Posted 2 May 2019, 11:31 pm EST

    When using a custom class as a value for a cell, an addition formula works and a SUM() formula does not.

    Here is my example (with a form with a spread on it)

    
    Imports FarPoint.Win.Spread.CellType
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            FpSpread1_Sheet1.Cells(0, 0, 3, 0).CellType = New NumberCellType
            FpSpread1_Sheet1.Cells(0, 0).Value = New negativeIntegerItemType(-1)
            FpSpread1_Sheet1.Cells(1, 0).Value = New negativeIntegerItemType(-2)
            FpSpread1_Sheet1.Cells(2, 0).Formula = "SUM(R1C1:R2C1)"                 'this fails
            FpSpread1_Sheet1.Cells(3, 0).Formula = "+R1C1+R2C1"                     'this works
        End Sub
    End Class
    Public Structure negativeIntegerItemType
        Implements IConvertible
        Private _value As Integer
        Public Property value As Integer
            Get
                Return _value
            End Get
            Set(value As Integer)
                If value < 0 Then
                    _value = value
                Else
                    Throw New OverflowException
                End If
            End Set
        End Property
        Default Property myProperty(ByVal index As Integer) As Integer
            Get
                Return _value
            End Get
            Set(val As Integer)
                value = val
            End Set
        End Property
        Public Sub New(value As Integer)
            Me.value = value
        End Sub
        Public Shared Widening Operator CType(ByVal s As String) As negativeIntegerItemType
            Dim val As Integer
            If Integer.TryParse(s, val) AndAlso val < 0 Then
                Return New negativeIntegerItemType(val)
            Else
                Throw New OverflowException
            End If
        End Operator
        Public Overrides Function ToString() As String
            Return value.ToString()
        End Function
        Public Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
            Return TypeCode.Double
        End Function
    
        Public Function ToBoolean(provider As IFormatProvider) As Boolean Implements IConvertible.ToBoolean
            Throw New NotImplementedException()
        End Function
    
        Public Function ToChar(provider As IFormatProvider) As Char Implements IConvertible.ToChar
            Throw New NotImplementedException()
        End Function
    
        Public Function ToSByte(provider As IFormatProvider) As SByte Implements IConvertible.ToSByte
            Throw New NotImplementedException()
        End Function
    
        Public Function ToByte(provider As IFormatProvider) As Byte Implements IConvertible.ToByte
            Throw New NotImplementedException()
        End Function
    
        Public Function ToInt16(provider As IFormatProvider) As Short Implements IConvertible.ToInt16
            Throw New NotImplementedException()
        End Function
    
        Public Function ToUInt16(provider As IFormatProvider) As UShort Implements IConvertible.ToUInt16
            Throw New NotImplementedException()
        End Function
    
        Public Function ToInt32(provider As IFormatProvider) As Integer Implements IConvertible.ToInt32
            Throw New NotImplementedException()
        End Function
    
        Public Function ToUInt32(provider As IFormatProvider) As UInteger Implements IConvertible.ToUInt32
            Throw New NotImplementedException()
        End Function
    
        Public Function ToInt64(provider As IFormatProvider) As Long Implements IConvertible.ToInt64
            Return value
        End Function
    
        Public Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
            Return CULng(value)
        End Function
    
        Public Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
            Return value
        End Function
    
        Public Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble
            Console.WriteLine("ToDouble:{0}", value.ToString)
            Return value
        End Function
    
        Public Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
            Return value
        End Function
    
        Public Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
            Throw New NotImplementedException()
        End Function
    
        Public Overloads Function ToString(provider As IFormatProvider) As String Implements IConvertible.ToString
            Throw New NotImplementedException()
        End Function
    
        Public Function ToType(conversionType As Type, provider As IFormatProvider) As Object Implements IConvertible.ToType
            Throw New NotImplementedException()
        End Function
    End Structure
    
    
  • Posted 6 May 2019, 4:03 pm EST

    Hi,

    Thanks for the sample code. We’ve asked the developers to look into this case [Internal Tracking ID: 272313]

    We’ll update this thread as soon as we get any information from them.

    Regards,

    Jitender

  • Posted 7 May 2019, 8:09 pm EST

    Hi,

    The new calculation engine (introduced from v11) work with primitive types only. A custom object won’t be processed by most functions.

    Can you please explain your scenario for using custom objects in calculations so we can consider adding support for custom objects in later versions?

    Thanks,

    Jitender

  • Posted 8 May 2019, 5:29 am EST

    At its simplest, I use a custom PaintCell override that combines formatting information saved in a given cell’s row and column header value (another custom value class). I use a custom data model to load the cell Row and Column values into the custom object during the data model GetValue function. Now the PaintCell sub knows the row and column of the cell to query the row/column header values for formatting info.

    -Kingman

  • Posted 8 May 2019, 4:06 pm EST

    Hi,

    Thanks for sharing the information. We’ve conveyed this to the developers. We’ll let you know when we get an update from them.

    Regards,

    Jitender

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels