Create custom celltype not derived from existing one

Posted by: c12008 on 8 September 2017, 3:13 pm EST

  • Posted 8 September 2017, 3:13 pm EST

    Hi,

    I want to create a custom cell type NOT derived from any existing spread celltype.
    What I need is a "MultiCheckboxCelltype" like the existing MultiOptionCelltype. The checkboxes should be visible all the time like the standard checkbox celltype - that means I do not want a celltype having my checkboxes existing in a subeditor only. They should be visible all the time.

    So I created a Winforms usercontrol containing a few checkboxes.
    Then I created a new celltype class implementing the ICelltype interface using my new usercontrol. But I have no idea what properties or methods comming with the ICelltype inteface have to return what kind of value or what method have to do what. Especially I don´t know how to "show" my usercontrol in the spreads cell. Obviously I have to fill the method "PaintCell" with some code but don´t know which one.

    Please find attached my usercontrol and my new celltype class.

    I would appreciate any tip to get it running.

    Regards
    c12008

    2014/05/MultiCheckBox.zip
  • Replied 8 September 2017, 3:13 pm EST

    Hi,

    does anyone has an idea to solve my issue?

    Regards
    c12008
  • Replied 8 September 2017, 3:13 pm EST

    Hi,

    Sorry for the delayed reply! It's a great question and taking a little longer than usual to process due to the complexity. I think a blog post example showing how to implement this is better, as there are a lot of points to make about it, and it would be very useful for other customers. I will post a complete example cell type in a blog post next week, and post a link to it here in another reply.

    Here are some quick answers to your questions:

    "I don´t know how to "show" my usercontrol in the spreads cell."

    Spread will show the control in the cell if you return the control instance from the IEditor.GetEditorControl method in the cell type. Your code is just returning nothing, so the cell never shows any editor because Spread thinks your custom cell type is not editable (that's what returning null from GetEditorControl means).

    "I have to fill the method "PaintCell" with some code but don´t know which one."

    You need to put code there to draw the control in the cell when it's not being edited. For your case, that code can use ControlPaint and Graphics.DrawString to draw the cell like the check box controls.

    The built-in cell types handle their drawing in static paint methods that are called from both PaintCell and the Paint event; you might want to consider taking that approach in your user control instead of using check box controls (less controls means less handles used). It's also much easier to get the same results in the cell when edit mode is on or off when you handle the drawing yourself in the control.

    There are a number of other considerations about making such a cell type, like implementing support for IReuseEditorControl2 to share the editor control instance between cells instead of creating a new one for each cell type instance, which I will cover in the blog post. For more info about those interfaces, please see here:

    http://helpcentral.componentone.com/NetHelp/SpreadNet7/WF/webframe.html#FarPoint.Win.Spread~FarPoint.Win.Spread.CellType.IReuseEditorControl_members.html
    http://helpcentral.componentone.com/NetHelp/SpreadNet7/WF/webframe.html#FarPoint.Win.Spread~FarPoint.Win.Spread.CellType.IReuseEditorControl2_members.html

    I also suggest it's much better to make a custom cell type that inherits from BaseCellType (at least, if you want it to integrate well with Spread) because that base class has many helper methods and built-in logic to handle many aspects of integration with Spread, like GetReusableEditorControl:

    http://helpcentral.componentone.com/NetHelp/SpreadNet7/WF/webframe.html#FarPoint.Win.Spread~FarPoint.Win.Spread.CellType.BaseCellType~GetReusableEditorControl.html

    I will cover that in the blog post too. Sorry again for the delay!
  • Marked as Answer

    Replied 8 September 2017, 3:13 pm EST

    Hi,

    yes, a complete example cell type would be great.
    I´m looking forward to next week.

    Regards
    c12008
  • Replied 8 September 2017, 3:13 pm EST

    Hi,

    Sorry for the long delay; it was more complicated that I thought!

    I have attached the updated sample. We made a few changes in your MultiCheckBox control to fix some issues. If you have any questions, please let me know. I'm still working on the blog post; I'll reply again when it's posted.
    2014/05/MultiCheckBoxCellType.zip
Need extra support?

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

Learn More

Forum Channels