StatusBar with custom cell value class

  • KingmanB 1 month, 2 weeks ago

    The new status bar feature looks great, but it doesn’t provide anything other than count when the value in the cell is a custom class, even if that class implements IConvertible. When the status bar iterates through the cells, how does it get the cell value, and can I get my class to provide it?
    Thanks

  • 11p
    Ruchir Agarwal11p 1 month, 2 weeks ago

    Hi,

    We could not replicate the issue at our end using “10.40.20162.0″ version of Spread.
    We have created a Class inheriting “NumberCellType” that shows negative number in red without any negative sign and the status bar seems to be working properly by showing Average, Sum and count of the selected range.
    I have attached the sample application used at our end, please modify the same and share back so that we can replicate the issue at our end and help you better.
    Also, you may like to refer to the following Blog demonstrating how to achieve the same functionality of showing average, sum etc using code: http://sphelp.grapecity.com/2014/12/18/summarizing-selected-cells-in-spread/

    Regards
    Ruchir Agarwal

    Attachments:
    You must be logged in to view attched files.
  • KingmanB 1 month, 2 weeks ago

    Hi,
    This has to do when the “value” not the “celltype” is a custom class. as in a simple project shown below:
    Imports FarPoint.Win.Spread
    Imports FarPoint.Win.Spread.CellType

    Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim ct As New classCellType
    For i = 0 To 9
    Dim c As New ClassVal
    c.str = “HI”
    c.value = i
    FpSpread1.Sheets(0).Cells(i, 2).CellType = ct
    FpSpread1.Sheets(0).Cells(i, 2).Value = c
    Next
    FpSpread1.Sheets(0).Cells(10, 2).Formula = (“C9+C3″)
    FpSpread1.Sheets(0).SelectionPolicy = Model.SelectionPolicy.MultiRange
    End Sub
    End Class
    Public Class classCellType
    Inherits NumberCellType
    Public Overrides Function Format(obj As Object) As String
    Dim negativeSign As String = System.Globalization.CultureInfo.InvariantCulture.NumberFormat.NegativeSign
    Dim formattedValue As String = MyBase.Format(obj)
    If formattedValue.StartsWith(negativeSign) Then
    formattedValue = formattedValue.Substring(negativeSign.Length, formattedValue.Length – negativeSign.Length)
    End If
    Return formattedValue
    End Function
    End Class
    Public Class ClassVal
    Implements IConvertible
    Public Property str As String
    Public Property value As Decimal
    Public Function GetTypeCode() As TypeCode Implements IConvertible.GetTypeCode
    Throw New NotImplementedException()
    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
    Throw New NotImplementedException()
    End Function

    Public Function ToUInt64(provider As IFormatProvider) As ULong Implements IConvertible.ToUInt64
    Throw New NotImplementedException()
    End Function

    Public Function ToSingle(provider As IFormatProvider) As Single Implements IConvertible.ToSingle
    Throw New NotImplementedException()
    End Function

    Public Function ToDouble(provider As IFormatProvider) As Double Implements IConvertible.ToDouble

    Return CDbl(value)
    End Function

    Public Function ToDecimal(provider As IFormatProvider) As Decimal Implements IConvertible.ToDecimal
    Return CDec(value)
    End Function

    Public Function ToDateTime(provider As IFormatProvider) As Date Implements IConvertible.ToDateTime
    Throw New NotImplementedException()
    End Function

    Public Function ToString1(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 Class

  • 11p
    Ruchir Agarwal11p 1 month, 2 weeks ago

    Hi,

    Thank you sharing the code.
    For showing the average, sum and count of the selected cells in StatusBar, you just need to modify your code’s

    FpSpread1.Sheets(0).Cells(i, 2).Value = c

    to

    FpSpread1.Sheets(0).Cells(i, 2).Value = c.value

    And everything should start working fine for you.

    I have attached sample application using your custom class for setting cell value and that shows Average, Sum etc properly in cell.

    Thanks & Regards
    Ruchir Agarwal

    Attachments:
    You must be logged in to view attched files.
  • KingmanB 1 month, 2 weeks ago

    I think you may be missing my point. . . The actual object that I wish to store in the cell value property is much more complex than the ClassVal I used in the example. The sheet displays the values , allows editing, allows formula’s with my custom cell type and cell value combination. Just placing the c.value in the cell doesn’t help. I am trying to figure out out the status bar extracts & calculates the (decimal?) values found in the cell.
    Thanks

  • 11p
    Ruchir Agarwal11p 1 month, 2 weeks ago

    Hello

    Since “c” is an object and cannot be cast directly into number, it is necessary there to assign “c.value” as cell’s value because StatusBar calculates Average and Sum on values of type Integer,Decimal etc
    Also, StatusBar extracts the Sum, Average by checking their type and then calculates the corresponding values.
    If this still did not help, then we request you to please share your application so that we could look into it and provide you the solution.

    Let me know if I could not make myself clear enough.

    Regards
    Ruchir Agarwal

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to create new topics.