Percent cell type

Posted by: ashapournami on 8 September 2017, 1:30 pm EST

  • Posted 8 September 2017, 1:30 pm EST

    Hi


     The percent cell has the property that the value gets divided by 100.


    I want to restrict it so that when I load the spread from datatable whatever value is there in the datatable it comes in the spread cell( without getting multiplied by 100 if its a percent cell)


     Thanks


    Asha

  • Replied 8 September 2017, 1:30 pm EST

    Asha,


    The PercentCellType is taking the value in the DataModel and Formatting it as a percentage. Thus, the value .87 formats as 87% and the value 87 would format as 8700%. If your values in the database are integer values that you want to display as a percentage, you would need to create a custom celltype that you override the Format and Parse methods to provide your own code.


    Public Class myPercentage


    Inherits FarPoint.Win.Spread.CellType.PercentCellType


    Public Overrides Function GetEditorValue() As Object


    Dim val As Integer


    val = CInt(MyBase.GetEditorValue() * 100)


    Return val


    End Function


    Public Overrides Sub SetEditorValue(ByVal value As Object)


    Dim val As Double


    If Not value Is Nothing Then


    val = value / 100


    End If


    MyBase.SetEditorValue(val)


    End Sub


    Public Overrides Function Format(ByVal obj As Object) As String


    Dim val As Double


    If Not obj Is Nothing Then


    val = obj / 100


    End If


    Return MyBase.Format(val)


    End Function


    Public Overrides Function Parse(ByVal s As String) As Object


    Dim val As Double


    val = MyBase.Parse(s)


    Return CInt(val * 100)


    End Function


    End Class

  • Replied 8 September 2017, 1:30 pm EST

    Hi


    Thanks. Can I have an option to set the max, min sizes of this cell.


    Thanks


    Asha

  • Replied 8 September 2017, 1:30 pm EST

    Since the class is inherited you should still have those options available...

    Dim p As New myPercentage
    p.MaximumValue = 0.3

  • Replied 8 September 2017, 1:30 pm EST

    Thanks a Lot for the solution. It worked


    Thanks


    Asha

Need extra support?

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

Learn More

Forum Channels