Can't make "Determining which cell receives DragDrop event with GetCellFromPixel" work.

Posted by: jhoover on 8 September 2017, 12:34 pm EST

  • Posted 8 September 2017, 12:34 pm EST

    I'm trying to determine what Cell a TreeNode is DragDrop'ed into (code below). GetCellFromPixel() never returns a valid (row,col) but it's off by one sometimes in row and/or column. (An offset of -44,-30 seems to work for right now, but what should I be getting the offset from?)


             private void fpSpread1_DragDrop(object sender, DragEventArgs e)
            {
                string[] a = e.Data.GetFormats();
                if (e.Data.GetDataPresent(typeof(TreeNode)))
                {
                    object o = e.Data.GetData(typeof(TreeNode));
                    TreeNode dropped = o as TreeNode;
                    FpSpread s = sender as FpSpread;
                    if (s != null && dropped != null)
                    {
                        CellRange dropTarg = new CellRange(0, 0, 0, 0);
                        Point cp = PointToClient(new Point(e.X, e.Y));
                        dropTarg = s.GetCellFromPixel(0, 0, cp.X,cp.Y);

                        if (dropTarg.Row >= 0 && dropTarg.Column >= 0)
                        {
                            Cell destCell = s.ActiveSheet.Cells[dropTarg.Row, dropTarg.Column];
                            //string dest = s.ActiveSheet.Cells[destCell.Row.Index, 1].Text.ToString();
                            s.ActiveSheet.Cells[dropTarg.Row, dropTarg.Column].Text = dropped.Text;
                        }
                    }
                }

            } 


    Thanks,


    Jeff

  • Replied 8 September 2017, 12:34 pm EST

    Jeff,


    When calling the PointToClient function, call it on the FpSpread control to map the x and y coordinates to Spread coordinates.


    Point cp = s.PointToClient(new Point(e.X, e.Y));

  • Replied 8 September 2017, 12:34 pm EST

    Perfect!


    Thank you!

Need extra support?

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

Learn More

Forum Channels