Paste problem when subclassing ComboBoxCellType

Posted by: daniels-fp on 8 September 2017, 3:02 pm EST

  • Posted 8 September 2017, 3:02 pm EST

    Hi,

    When subclassing ComboBoxCellType and applying instances of the new cell type on multiple cells, copy/paste between the cells doesn't work.
    Copy/paste work if the new cell type is set on the column level, but not on a cell level.
    Here is a short example that demonstrate the problem (also attached a VS2010 solution):

     

    public MainForm()
    {
       InitializeComponent();
       InitSpread();
       fpSpread1.AutoClipboard = true;

       var col1Combo = new MyComboBoxCellType(); // Paste works.
       col1Combo.Items = new[] { "foo", "bar"};
       fpSpread1_Sheet1.Columns.Get(0).CellType = col1Combo;

       for(int i=0; i<10; i++)
       {
          var col2Combo = new MyComboBoxCellType(); // Paste doesn't work (but DO work when changing to "new ComboBoxCellType()")
          col2Combo.Items = new[] { "hello", "world" };

          Cell cellCol2 = fpSpread1_Sheet1.Cells[i, 1];
          cellCol2.CellType = col2Combo;
          cellCol2.Value = (i % 2 == 0 ? col2Combo.Items.First() : col2Combo.Items.Last());            

          Cell cellCol1 = fpSpread1_Sheet1.Cells[i, 0];
          cellCol1.Value = (i % 2 == 0 ? col1Combo.Items.First() : col1Combo.Items.Last());
       }
    }

    public class MyComboBoxCellType : ComboBoxCellType
    {
       // Empty subclass of ComboBoxCellType.
    }

     

    Copy/paste in the first column works fine, select a "foo" cell using the arrow keys, press Ctrl+C, select a "bar" cell, press Ctrl+V.
    Copy/paste in the second column doesn't work (i.e. from "hello" to "world"), pasting a "hello" from Notepad however works. It also works if the second column uses the ComboBoxCellType class instead of the sub class (even though it's empty). When overriding OnClipboardPasting and OnClipboardPasted on the spread, the OnClipboardPasting method is called but never OnClipboardPasted.

    Tested with Spread for Windows Forms 5.0.3518.2008 VS2010/.NET4 on Windows 7.

    Any help would be appreciated.
    Seems like a bug to me, but let me know if there's a workaround.
    Thanks! 

     

     


    2012/11/CopyPasteSpreadTest.zip
  • Replied 8 September 2017, 3:02 pm EST

    Hello,

    I was able to replicate the issue at my end and the issue seems to be a bug. I have reported the issue to the development team and the bug number for the same is #99929847  . It would be fixed in the next maintenance release. As a workaround I would suggest you to handle the KeyDown even to get and set the cell value manually. Here is the code for the same:







    pre { font-family: "Liberation Serif"; }p { margin-bottom: 0.21cm; }

      void fpSpread1_KeyDown(object sender, KeyEventArgs e)
    {
    if (e.Control && e.KeyCode == Keys.C)
    {
    if (fpSpread1.ActiveSheet.ActiveCell.CellType.ToString() == typeof(MyCombo).Name)
    {
    obj = fpSpread1.ActiveSheet.ActiveCell.Value;
    }
    }
    if (e.Control && e.KeyCode == Keys.V)
    {
    if (obj != null)
    {
    fpSpread1.ActiveSheet.ActiveCell.Value = obj;
    obj = null;
    }
    }
    }
     

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 3:02 pm EST

    Thanks for a quick response and the workaround! I believe I can integrate the workaround with our current paste logic until your next maintenance release.
Need extra support?

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

Learn More

Forum Channels