DateTimeCellType issue with formatting.

Posted by: silkkeng-fp on 8 September 2017, 1:48 pm EST

  • Posted 8 September 2017, 1:48 pm EST

    Hi,

    We have create a new class which inherits DateTimeCellType to set the DateFormat.

    See attached project.

    The issues :

    #1.
    1.1.  Set  Values to Cell, e.g. 01/01/2009
    1.2.  Double click to turn cell into edit mode. Don't change value.
    1.3.  Click other place to exit edit mode.
    1.4.  The value hasn't been changed, but it revert back to Today's date.
    1.5.  Also, if now you click on the drop down button to manually select a date on the calendar, you can see that the calendar is still previous date value.
    This is a big strange. Any idea?

     

    #2.
    2.1.  As you can see we only change the FormatString, so Set Values to Cell, e.g. 01/01/2009.
    2.2.  Double click to turn cell into edit mode. Don't change value yet.
    2.3.  Press on home button to let the cell focus goes to the first char in the cell.
    2.4.  Start typing e.g. 2, (I want to change it to 21/01/2009). and you can see that whole cell value is gone.

    Is there a way to keep this values while doing changing?


    Regards,
    David

     


    2009/03/SpreadTest5.zip
  • Replied 8 September 2017, 1:48 pm EST

    Hi Kevin,
    Thanks for the advice.

    But, would you be able to provide example of changing formatting when edit mode off?

    The formatting is changed at subeditor or cell type?

     

    Thanks

     

  • Replied 8 September 2017, 1:48 pm EST

    I cannot follow your steps as certain things are missing from the sample. However, I can see several problems right off the bat. You are modifying the Formatter but only when you go into edit mode and only on the editing control and not the celltype. So upon entering edit mode an invalid value is being set into the editor and upon exiting edit mode the formatting of the data that exists in edit mode is failing because it doesn't fit with the formatter for the celltype.


    What you need to do is simply code the values of the properties to get the desired formats you'd like. If for some reason there is a necessity of having a different format inside and outside of edit mode than you would need to override many more of the celltype methods in order to get the two to function in unison with one another.

  • Replied 8 September 2017, 1:48 pm EST

    You may override the PaintCell method to specity the format of the data in the cell, when cell is not in edit mode.


    Regards,

  • Replied 8 September 2017, 1:48 pm EST

    Hi Scott,
    Thanks for the clarification.

    But, I found few issue when

    FpSpread1.Sheets(0).Cells(0, 0).CellType= New FarPoint.Win.Spread.CellType.DateTimeCellType (e.g. d/MM/yyyy)

    FpSpread1.Sheets(0).Cells(0, 0).Editor = New SimpleDateTimeCellType (e.g. dd/MM/yyyy)


    FpSpread1.Sheets(0).Cells(0, 0).Formater= New FarPoint.Win.Spread.CellType.DateTimeCellType

    FpSpread1.Sheets(0).Cells(0, 0).CellType will return nothing.

    Is this intended?

     

    And also, if 

    FpSpread1.Sheets(0).Cells(0, 0).Editor = New SimpleDateTimeCellType  (e.g. dd/MM/yyyy)

    FpSpread1.Sheets(0).Cells(0, 0).CellType= New FarPoint.Win.Spread.CellType.DateTimeCellType (e.g. d/MM/yyyy)

    The Editor's UserDefinedFormat will be overwritten by .CellType format.

    Is this intended?

     

    Thanks

    Sorry for the trouble.


     

     

  • Replied 8 September 2017, 1:48 pm EST

    Hello,


    You can not assign a Formatted to the SubEditor. The CellType object assigned to the Cell/Column will do the formatting. I think Kevin was suggesting instead of setting the CellType to an instance of your class, set the Editor property and then set the Formatter to an instance of an object to format the value as you like.


    FpSpread1.Sheets(0).Cells(0, 0).Editor = New SimpleDateTimeCellType


    FpSpread1.Sheets(0).Cells(0, 0).Formater= New FarPoint.Win.Spread.CellType.DateTimeCellType

  • Replied 8 September 2017, 1:48 pm EST

    The easiest means would be to set the Cells Editor property to one instance of a DateTimeCellType and it's Renderer to another instance instead of just setting the CellType for the cell.
  • Replied 8 September 2017, 1:48 pm EST

    Hi Kevin,

    I understand that this would work.

    But, we are assignining the cell type to whole columns.

    So, I was thinking of using a celltype with the combination of subeditor.

    Is this going to work?

    See example below.

    But, the problem is how do I set the formatter to subeditor?

    Let me know if I am taking the wrong approach or am i on the wrong track?

    Thanks

     

     


    2009/03/SpreadTest5-2.zip
  • Replied 8 September 2017, 1:48 pm EST

    Hi Scott,
    Thanks for your reply.

    Another quick things to check:

    I noticed that when in edit mode, if the date cell value is not highlighted, and start entering digit, it work properly.

    When a cell is entering and in edit mode (date cell value get highlighted), when you start entering a digit to change the day value,  it actually flip the month to current month.

    E.g. current value is 01/01/2009 and display as 1/1/2009.

    In edit mode and have the cell value is highlighted, start entering will change the value to 30/03/2009 instead of 30/01/2009.


    Is this intended behaviour as well?

    Thanks

     

     

  • Replied 8 September 2017, 1:48 pm EST

    Hello,


    I am not able to reproduce this issue. Here is the code I used to test this. Could you let me know what I need to change to reproduce the issue?


    Dim dt1 As New FarPoint.Win.Spread.CellType.DateTimeCellType


    Dim dt2 As New FarPoint.Win.Spread.CellType.DateTimeCellType


    dt1.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined


    dt1.UserDefinedFormat = "d/MM/yyyy"


    dt2.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined


    dt2.UserDefinedFormat = "dd/MM/yyyy"


    FpSpread1.Sheets(0).Cells(1, 1).CellType = dt1


    FpSpread1.Sheets(0).Cells(1, 1).Formatter = dt1


    FpSpread1.Sheets(0).Cells(1, 1).Editor = dt2


    FpSpread1.Sheets(0).Cells(1, 1).Value = #1/1/2009#

  • Replied 8 September 2017, 1:48 pm EST

    Hi Scott,

    I also noticed one weird issue when upgrade to 4.0.2015.2005.

    I have my

    Editor = dd/MM/YYYY
    Formater = d/MM/YYYY

    My current cell value is 1/01/2009

    In new build:

    When I start entering number 3 to make it 31/01/2009
    it actually skip the 3 and focus goes to 1, then i have to press on left arrow key back again to set the 3 to become 31/01/2009.

    In build 4.0.2003.2005,

    When I start entering number 3 to make it 31/01/2009,

    it actually did set it to 31/01/2009.

  • Replied 8 September 2017, 1:48 pm EST

    Hello,


    This is intended behavior. When you have the entire date selected in editmode and type a number, the date that was in the cell is removed (overwritten) and since this is a DateTime field and there has to be a valid date in the editor at all times, the editor uses the default value for the editor (usually today's date) and fills in the parts of the editor that are not valid with values from this date.

  • Replied 8 September 2017, 1:48 pm EST

    Hello,


    Both are 'As Intended'. Setting the CellType property is a quick way to set the Editor, Renderer, and Formatter properties. So, in the first sample, by you assigning an Editor or Formatter to the Cell, the CellType object is removed. And the same in the second option. Setting the CellType property overwrites the editor on the cell.

Need extra support?

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

Learn More

Forum Channels