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:

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2>public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>class</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>CustomCellType1</FONT><FONT size=2> : FarPoint.Win.Spread.CellType.</FONT><FONT color=#2b91af size=2>NumberCellType

    </FONT><FONT size=2>

    {


    </FONT><FONT color=#008000 size=2>//public CustomCellType1()

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//{

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// DecimalPlaces = 6;

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// FixedPoint = false;

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//}

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//{

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// if (!(value == null))

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// {

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// value = ((double)value).ToString("N6");

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// }

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//}

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//public override string Format(object obj)

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//{

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>// return obj.ToString();

    </FONT><FONT size=2>

    </FONT><FONT color=#008000 size=2>//}

    </FONT><FONT size=2>

    }


     


    Here is how I use the custom class:

    <FONT size=2>

    </FONT><FONT color=#2b91af size=2>line 1: CustomCellType1</FONT><FONT size=2> nct = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#2b91af size=2>CustomCellType1</FONT><FONT size=2>();


    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!


     

    </FONT></FONT>
  • 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.

     
    	<SPAN class=kwd>public class</SPAN> CustomCellType1 : FarPoint.Win.Spread.CellType.NumberCellType
    {

    FarPoint.Win.Spread.CellType.GeneralEditor ge;

    <SPAN class=kwd>public</SPAN> CustomCellType1()
    {
    <SPAN class=cmt>//DecimalPlaces = 6;</SPAN>
    FixedPoint = <SPAN class=kwd>false</SPAN>;
    }

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

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

    <SPAN class=kwd>public override object</SPAN> GetEditorValue()
    {
    <SPAN class=kwd>return decimal</SPAN>.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