NumberCellType and specific length to force 01, 02 instead of 1, 2

Posted by: j2associates on 8 September 2017, 1:57 pm EST

  • Posted 8 September 2017, 1:57 pm EST

    Hello all,


    Is there a way to have a NumberCellType return a specific length? For instance, I need my int NumberCellType to return 2 bytes (eg 01, 02, 21, 22, etc). Thanks in advance for any ideas and/or suggestions!

  • Replied 8 September 2017, 1:57 pm EST

    Hello,


    NumberCellType doesn't have any method or property to return a Specific length. You can use MaskCellType where you should be able to set the format for the value entered.


     


    Thanks,


     

  • Replied 8 September 2017, 1:57 pm EST

    Can you give me some sample code to get me started. Basically, the range of allowable numbers is 1-99 and for numbers less than 10, they need to display as 01, 02, etc instead of 1, 2, etc. Thanks in advance for any ideas and/or suggestions!
  • Replied 8 September 2017, 1:57 pm EST

    Out of curiosity would you want this both in edit mode and out or only after editing is complete?
  • Replied 8 September 2017, 1:57 pm EST

    Preferably after edit is complete for display purposes. I don't want the user to have to mess around with leading zeroes. So going into edit mode it would be a plain integer and coming out it would be formatted with the leading zeroes. Thanks for the response...
  • Replied 8 September 2017, 1:57 pm EST

    Hello,


    As I suggested earlier it is possible using the MaskCellType Below is the code snippet to apply this to a cell,


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    Dim mask As New FarPoint.Win.Spread.CellType.MaskCellType


    mask.Mask = "##"


    mask.MaskChar = " "


    FpSpread1.ActiveSheet.Columns(2).CellType = mask


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim ret As Integer


    ret = CType(FpSpread1.Sheets(0).GetText(2, 2), Integer)


    If ret < 10 Then


    FpSpread1.Sheets(0).Cells(2, 2).Text = "0" & ret


    End If


    End Sub


     


    Hope it will help you. 


    Thanks,

Need extra support?

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

Learn More

Forum Channels