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

    <P>Hello all,</P>
    <P>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!</P>
  • Replied 8 September 2017, 1:57 pm EST

    <P>Hello, </P>
    <P>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.</P>
    <P> </P>
    <P>Thanks,</P>
    <P> </P>
  • 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

    <P>Hello,</P>
    <P>As I suggested earlier it is possible using the MaskCellType Below is the code snippet to apply this to a cell,</P><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
    <P>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</P>
    <P></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</P>
    <P>mask.Mask = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"##"</P></FONT></FONT><FONT size=2>
    <P>mask.MaskChar = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>" "</P></FONT></FONT><FONT size=2>
    <P>FpSpread1.ActiveSheet.Columns(2).CellType = mask</P>
    <P></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</P></FONT></FONT><FONT size=2>
    <P></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</P>
    <P></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</P></FONT></FONT><FONT size=2>
    <P>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>)</P>
    <P></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</P></FONT></FONT><FONT size=2>
    <P>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</P>
    <P></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</P></FONT></FONT><FONT size=2>
    <P></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</P>
    <P> </P></FONT></FONT>
    <P>Hope it will help you. </P>
    <P>Thanks,</P>
Need extra support?

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

Learn More

Forum Channels