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