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,

    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> Form1_Load(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>MyBase</FONT></FONT><FONT size=2>.Load


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> mask </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> FarPoint.Win.Spread.CellType.MaskCellType


    mask.Mask = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"##"

    </FONT></FONT><FONT size=2>

    mask.MaskChar = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>" "

    </FONT></FONT><FONT size=2>

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


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> Button1_Click(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> Button1.Click


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> ret </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer

    </FONT></FONT><FONT size=2>

    ret = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>CType</FONT></FONT><FONT size=2>(FpSpread1.Sheets(0).GetText(2, 2), </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Integer</FONT></FONT><FONT size=2>)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> ret < 10 </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then

    </FONT></FONT><FONT size=2>

    FpSpread1.Sheets(0).Cells(2, 2).Text = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"0"</FONT></FONT><FONT size=2> & ret


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub


     

    </FONT></FONT>

    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