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


    maskCell.Mask = "######";
    maskCell.NullDisplay =
    "______";


    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.
    I want the value to be "______" if there is nothing entered, how do i solve this?



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


    if(cellIsNullOrSomethingLikeThat)
    value="______"


    BR
    Magnus

  • 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 Spread for Window Forms 5.0 solve the problem? 

  • 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:
    spreadParams.ActiveSheet.GetValue(i,1) throws a NullRef exception if I don't enter anything in that cell. i want the value to be "______"


    sorry for being unclear.


    br
    Magnus

  • 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

    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 :



     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 = "______";


    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