how to use NullDisplay if value is null in MaskCellType

Posted by: bodin on 8 September 2017, 2:10 pm EST

  • Posted 8 September 2017, 2:10 pm EST

    I have a problem with a MaskCellType

    <FONT size=2>

    maskCell.Mask = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"######"</FONT></FONT><FONT size=2>;
    maskCell.NullDisplay = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"______"</FONT></FONT><FONT size=2>;</FONT>


    <FONT size=2>If I enter only one number like this "1_____", this comlete value string will look exactly like that but if don't enter anything in the cell, the value is null.
    </FONT>I want the value to be "______" if there is nothing entered, how do i solve this?


    <DIV class=ForumPostContentText id=_ctl0__ctl1_bcr__ctl0___PostRepeater__ctl2_PostViewWrapper>

    I create the cells with different types and masks in maskcells dynamicly so i can't just do like


    if(cellIsNullOrSomethingLikeThat)
    value="______"

    </DIV>

    <FONT size=2>BR
    Magnus</FONT><FONT size=2>

    </FONT>
  • Replied 8 September 2017, 2:10 pm EST

    Magnus,


    I tested the following code and it worked as you expected. Make sure you are using the latest maintenance release of Spread for Windows Forms.


      Dim m As New FarPoint.Win.Spread.CellType.MaskCellType
      m.Mask = "######"
      m.NullDisplay = "______"
      'm.MaskChar = "_"
      FpSpread1.Sheets(0).Cells(1, 1).CellType = m

  • Replied 8 September 2017, 2:10 pm EST

    That is exacly how my code looks.


    I'm using version 4.0.
    Will an upgrade to <SPAN style="COLOR:black;">Spread for Window Forms 5.0 solve the problem?</SPAN><SPAN style="COLOR:black;"> </SPAN>

  • Replied 8 September 2017, 2:10 pm EST

    Hello,


    I tested with the latest maintenance release of Spread for Windows Forms 4 (version 4.0.2012). This should work for you. If it is not, could you post a small zipped project reproducing this behavior for us to debug?

  • Replied 8 September 2017, 2:10 pm EST

    my problem is not to display "______" in the cell. the problem is to pick up that value/text from the cell if I just leave it as it is.


    here is my actual problem:
    <FONT size=2>spreadParams.ActiveSheet.GetValue(i,1) throws a NullRef exception if I don't enter anything in that cell. i want the value to be "______"</FONT>


    sorry for being unclear.


    br
    Magnus<FONT size=2>

    </FONT>
  • Replied 8 September 2017, 2:10 pm EST

    Hello,


    You can put a null check to check if the cell has value or not else you can display "____". Code for the same is as follows :


    <BLOCKQUOTE>

     if (fpSpread1.Sheets[0].Cells[i, 1].Value != null)
              fpSpread1.Sheets[0].Cells[2, 2].Value = fpSpread1.Sheets[0].GetValue(0, 0);
     else
              fpSpread1.Sheets[0].Cells[2, 2].Value = "______";

    </BLOCKQUOTE>

    Hope it will help. Thanks.


     

  • Replied 8 September 2017, 2:10 pm EST

    Hello,


    You can use the Format method of the CellType to give you the result you are looking.


      Dim c As FarPoint.Win.Spread.CellType.ICellType = FpSpread1.ActiveSheet.GetCellType(i, 1)
      MessageBox.Show(c.Format(FpSpread1.ActiveSheet.GetValue(i, 1)))


     

Need extra support?

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

Learn More

Forum Channels