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

    <P>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?)</P>
    <P>         <SPAN class=kwd>private void</SPAN> fpSpread1_DragDrop(<SPAN class=kwd>object</SPAN> sender, DragEventArgs e)<BR>        {<BR>            <SPAN class=kwd>string</SPAN>[] a = e.Data.GetFormats();<BR>            <SPAN class=kwd>if</SPAN> (e.Data.GetDataPresent(<SPAN class=kwd>typeof</SPAN>(TreeNode)))<BR>            {<BR>                <SPAN class=kwd>object</SPAN> o = e.Data.GetData(<SPAN class=kwd>typeof</SPAN>(TreeNode));<BR>                TreeNode dropped = o <SPAN class=kwd>as</SPAN> TreeNode;<BR>                FpSpread s = sender <SPAN class=kwd>as</SPAN> FpSpread;<BR>                <SPAN class=kwd>if</SPAN> (s != <SPAN class=kwd>null</SPAN> && dropped != <SPAN class=kwd>null</SPAN>)<BR>                {<BR>                    CellRange dropTarg = <SPAN class=kwd>new</SPAN> CellRange(0, 0, 0, 0);<BR>                    Point cp = PointToClient(<SPAN class=kwd>new</SPAN> Point(e.X, e.Y));<BR>                    dropTarg = s.GetCellFromPixel(0, 0, cp.X,cp.Y);<BR><BR>                    <SPAN class=kwd>if</SPAN> (dropTarg.Row >= 0 && dropTarg.Column >= 0)<BR>                    {<BR>                        Cell destCell = s.ActiveSheet.Cells[dropTarg.Row, dropTarg.Column];<BR>                        <SPAN class=cmt>//string dest = s.ActiveSheet.Cells[destCell.Row.Index, 1].Text.ToString();</SPAN><BR>                        s.ActiveSheet.Cells[dropTarg.Row, dropTarg.Column].Text = dropped.Text;<BR>                    }<BR>                }<BR>            }<BR><BR>        } </P>
    <P>Thanks,</P>
    <P>Jeff</P>
  • Replied 8 September 2017, 12:34 pm EST

    <P>Jeff,</P>
    <P>When calling the PointToClient function, call it on the FpSpread control to map the x and y coordinates to Spread coordinates.</P>
    <P>Point cp = s.PointToClient(<SPAN class=kwd>new</SPAN> Point(e.X, e.Y));</P>
  • Replied 8 September 2017, 12:34 pm EST

    <P>Perfect!</P>
    <P>Thank you!</P>
Need extra support?

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

Learn More

Forum Channels