.0 is added to Value property in NumberCellType with 0 decimals

Posted by: kung-carl on 8 September 2017, 1:10 pm EST

  • Posted 8 September 2017, 1:10 pm EST

    Hi,


    I have a column in a spread (Spread for Winforms 4) with celltype set as NumberCellType and property DecimalPlaces set to 0.


    When the user in runtime adds a number in a cell, the Value property of the cell gets a ending .0 (e.g. 100.0 after typing 100). This decimal is not displayed but causes problems as I somtimes programatically sets the value (without .0). When the user then tabs pass the cell the CellChanged event fires as the spread now has added the .0 decimal in the Value property.


    How can I avoid this .0?


    Thanks


    Michael

  • Replied 8 September 2017, 1:10 pm EST

    Michael -

    I am not able to reproduce this behavior.  If I set up a NumberCellType with 0 decimal places and put the value 100 in the cell and then tab past that cell the CellChanged event never fires.  Could you post a small project reproducing this for us to debug?
  • Replied 8 September 2017, 1:10 pm EST

    I've sent you the code.


    The problem occurs if You put 100 in the cell by code and not by entering it in the spread. After that if you just tab pass the cell (in my case I have EditModePermanent and EditModeReplace set to true) the event will fire as when adding the value within the spread it adds .0 to the .Value property but when adding it by code it dont.


    //Michael

  • Replied 8 September 2017, 1:10 pm EST

    Ok ,


    I can see that the value is changed to 10.0 by adding a breakpoint and checking the Value property of the cell.


    //Michael

  • Replied 8 September 2017, 1:10 pm EST

    Michael -

    I do see the CellChanged event firing when tabbing which I don't think should be happening.  I will look into that issue.  But I do not see the value changing to 10.0
  • Replied 8 September 2017, 1:10 pm EST

    Michael -

    Using your code I am still not seeing this behavior.  If you reply to a post there is an 'Option' tab at the top.  If you click that it will bring you to a page where you can add your project.
  • Replied 8 September 2017, 1:10 pm EST

    Michael -

    I do see that with a breakpoint in the code.  It's getting parsed as a Double for some reason when tabbing across the cell.  I will investigate both these issues to make sure they are bugs and post my results.
  • Replied 8 September 2017, 1:10 pm EST

    Michael,


    You are confusing the text representation of a number (type String) with the binary representation of a number (type Double).  When CellType = NumberCellType, the cell's value is entered by the user and is displayed on the screen in a text representation but is stored in the cell in a binary representation.  The cell Value property returns the binary representation.  When you display the number in a MessageBox or command window, the application code or IDE is converting the number into a text representation for display (both "10" and "10.0" are valid text representations of the number 10.0).  If you want the text representation of the number as displayed in the cell then you can use the cell's Text property.

  • Replied 8 September 2017, 1:10 pm EST

    Michael -

    The issue with the CellChanged event firing when tabbing over the cell I will write up as a bug.  For some reason that cell is being flagged as dirty.

    The issue with the 10.0 being displayed is the correct behavior.  When you leave edit mode(which is what's happening when you tab off that cell) the editor of the NumberCellType is parsing the value in the textbox(of our control) and converting it as a double in the data model.  I'm not sure what you are wanting to do but if you don't want this behavior then you can use the GeneralCellType and the number should remain as an Integer.  Or you can create a custom number celltype and in the Parse and Format methods return an Integer instead of a double.
  • Replied 8 September 2017, 1:10 pm EST

    That's what I'm doing in the event...

    Private Sub FpSpread1_Sheet1_CellChanged(ByVal sender As Object, ByVal e As FarPoint.Win.Spread.SheetViewEventArgs) Handles FpSpread1_Sheet1.CellChanged
    MsgBox(FpSpread1.ActiveSheet.Cells(e.Row, e.Column).Value)
    End Sub
  • Replied 8 September 2017, 1:10 pm EST

    Thats true that You dont see it when displaying it in a MessageBox but if you check the value by e.g. the command window when reaching the breakpoint (? fpSpread1.Cells[0,1].Value) it says 10.0.

  • Replied 8 September 2017, 1:10 pm EST

    Ok,  I understand.


    My problem is that theCellChange event fires if i set the cell Value property by code and the user thereafter tabs through the cell (if user is entering the same value in runtime by typing it into the cell the evnt isn't fired next time he tabs pass the cell)


    However I'll try solving it by using another celltype.


    By the way, thanks a lot for very fast replies. It's my first time adding a question in the forum and I'm very impressed Big Smile [:D]


    //Michael

Need extra support?

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

Learn More

Forum Channels