Problem in creating derived custom cell type from NumberCellType class

Posted by: hdang on 8 September 2017, 12:55 pm EST

  • Posted 8 September 2017, 12:55 pm EST

    Hello,


    Using Win Spread for .NET version 2.5xxxx


    I want to create a custom cell type in order to allow the user to type in full value of a number while displaying fixed decimal point.  I am having weird crashing.  So I commented out all the derived methods just to see what the problem is.  Here is my class definition:


    public class CustomCellType1 : FarPoint.Win.Spread.CellType.NumberCellType


    {


    //public CustomCellType1()


    //{


    // DecimalPlaces = 6;


    // FixedPoint = false;


    //}


    //public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)


    //{


    // if (!(value == null))


    // {


    // value = ((double)value).ToString("N6");


    // }


    // base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);


    //}


    //public override string Format(object obj)


    //{


    // return obj.ToString();


    //}


    }


     


    Here is how I use the custom class:


    line 1: CustomCellType1 nct = new CustomCellType1();


    line 2: nct.DecimalPlaces = m_decimalPlaces;


    line 3: sv.Cells[r.Index, col.Index].CellType = nct;


     


    And here is what the exception error at line 2 saying:


    Unable to cast object of type 'FarPoint.Win.SuperEdit.MaskFormatter' to type 'FarPoint.Win.SuperEdit.MaskFormatter'


     


    Am I doing anything wrong or missing something?  My CustomCellType1 class doesn't do anything!  It inherited from NumberCellType and that's it!


     

  • Replied 8 September 2017, 12:55 pm EST

    Hello,


    Make sure you have the latest maintenance release of Spread for Windows Forms. You should not be getting an exception. Here is changes I made to your class to give the functionality you are looking.

     
    	public class CustomCellType1 : FarPoint.Win.Spread.CellType.NumberCellType
    {

    FarPoint.Win.Spread.CellType.GeneralEditor ge;

    public CustomCellType1()
    {
    //DecimalPlaces = 6;
    FixedPoint = false;
    }

    public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
    {
    if (!(value == null))
    {
    value = ((decimal)value).ToString("N6");
    }
    base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
    }

    public override Control GetEditorControl(FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
    {
    ge = (FarPoint.Win.Spread.CellType.GeneralEditor)base.GetEditorControl(appearance, zoomFactor);
    ge.Formatter = null;
    return ge;
    }

    public override object GetEditorValue()
    {
    return decimal.Parse(ge.Value.ToString());
    }
    }
     
Need extra support?

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

Learn More

Forum Channels