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?)

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

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




  • Replied 8 September 2017, 12:34 pm EST


    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(<SPAN class=kwd>new</SPAN> Point(e.X, e.Y));

  • Replied 8 September 2017, 12:34 pm EST


    Thank you!

Need extra support?

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

Learn More

Forum Channels