How to drag data from a TreeView and drop into a FP Sheet

Posted by: luigggye-fp on 8 September 2017, 2:24 pm EST

  • Posted 8 September 2017, 2:24 pm EST

    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Hi<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>I have a TreeView with data that I want to place into some ROW / COL in a FP Sheet, using the drag and drop operation.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>I must to place the source information (TreeView item dragged) into the cell (FP Sheet ROW / COL) that corresponds with the coordinates of the mouse when the drop is done.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>My problem is that I can´t get the current ROW / COL index, while the drag operation is in progress.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;">Private</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> <SPAN style="COLOR:blue;">Sub</SPAN> FP_DragEnter(<SPAN style="COLOR:blue;">ByVal</SPAN> sender <SPAN style="COLOR:blue;">As</SPAN> <SPAN style="COLOR:blue;">Object</SPAN>, <SPAN style="COLOR:blue;">ByVal</SPAN> e <SPAN style="COLOR:blue;">As</SPAN> System.Windows.Forms.DragEventArgs) <SPAN style="COLOR:blue;">Handles</SPAN> FP.DragEnter<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><SPAN style="mso-spacerun:yes;">        </SPAN>e.Effect = DragDropEffects.Move<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><SPAN style="mso-tab-count:1;">       </SPAN><SPAN style="mso-spacerun:yes;"> </SPAN><o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><SPAN style="mso-tab-count:1;">       </SPAN><SPAN style="mso-spacerun:yes;"> </SPAN>HOW TO GET THE FP ACTIVE SHEET CELL (ROW AND COL) AT THIS MOMENT?<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;">End</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> <SPAN style="COLOR:blue;">Sub<o:p></o:p></SPAN></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;">Private</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> <SPAN style="COLOR:blue;">Sub</SPAN> FP_DragMove(<SPAN style="COLOR:blue;">ByVal</SPAN> sender <SPAN style="COLOR:blue;">As</SPAN> <SPAN style="COLOR:blue;">Object</SPAN>, <SPAN style="COLOR:blue;">ByVal</SPAN> e <SPAN style="COLOR:blue;">As</SPAN> System.Windows.Forms.DragEventArgs) <SPAN style="COLOR:blue;">Handles</SPAN> FP.DragOver<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><SPAN style="mso-spacerun:yes;">        </SPAN>e.Effect = DragDropEffects.Move<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><SPAN style="mso-tab-count:1;">       </SPAN><SPAN style="mso-spacerun:yes;"> </SPAN>HOW TO GET THE FP ACTIVE SHEET CELL (ROW AND COL) AT THIS MOMENT?<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;">End</SPAN><SPAN style="LINE-HEIGHT:115%;FONT-FAMILY:'Courier New';FONT-SIZE:8pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> <SPAN style="COLOR:blue;">Sub</SPAN></SPAN><SPAN style="LINE-HEIGHT:115%;FONT-SIZE:8pt;mso-ansi-language:EN-US;"><o:p></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Thanks in advance,<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Luigggye<o:p></o:p></FONT></FONT></SPAN>

  • Replied 8 September 2017, 2:24 pm EST

    Hello Luigggye,


    You can use the GetCellFromPixel method to get the row and column index of the active cell and then work accordingly.


    <BLOCKQUOTE>

               FarPoint.Win.Spread.Model.CellRange range = fpSpread2.GetCellFromPixel(0, 0, e.X, e.Y);
               MessageBox.Show("Range: Row=" + range.Row.ToString() + " Column=" + range.Column.ToString());

    </BLOCKQUOTE>

    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:24 pm EST

    Thanks so much for your response. It´s works fine in the body of the sheet. Excellent. !!


    Now I want to do the same in the header area.


    In other words, I must to be able to drop data into the row and column header too, and your suggestion do not works in this case.


    When I move the mouse over the row / col header area the row and col become "-1".


    Could you help me with it, please?


    Thanks in advance,


    Luigggye


     

  • Replied 8 September 2017, 2:24 pm EST

    Hello,

    This is the correct behavior, by default headers are not editable. In order to capture the header click you may catch the CellClick event as:

     If e.ColumnHeader Then
                MsgBox(e.Column & e.Row)
     End If

     Thanks,

     

     

     

  • Replied 8 September 2017, 2:24 pm EST

    Hello,


    The Spreadview's GetColumnHeaderCellFromPixel( ) method works fine in the FpSpread1.MouseUp event.


    But the FpSpread1.MouseUp event is only fired when I click over the FP Sheet and release the mouse over the Sheet.


    If I do the click outside the sheet (in my case a treeview node), then move the mouse to the sheet (FP.DragOver event is fired), then release (FP.DragDrop event is fired) the mouse in the sheet (anywhere) the FpSpread1.MouseUp event is not fired.


    <FONT size=2><FONT size=2>I already was tried the GetColumnHeaderCellFromPixel( ) method in the FP.DragOver / FP.DragDrop event but do not works (the row and col is -1).</FONT></FONT>


    I really need to drag data from a Treeview Node to a FP Sheet over any area (Header cells and Body cells), please see the attached sample of my interfase.


    Waiting for a solution.


    Thanks in advance,


    Luigggye



  • Replied 8 September 2017, 2:24 pm EST

    Luigggye,


    In order to catch the index of the row and column in ColumnHeader while the drag and drop operation is in progress you can use MouseMove event which occurs if the user moves the cursor while the cursor is over the element and that ways you will be able to know the ColumnHeader's row and column index and work accordingly.


    <BLOCKQUOTE>

     private void fpSpread1_MouseMove(object sender, MouseEventArgs e)
            {
                listBox1.Items.Add(fpSpread1.GetRootWorkbook().GetActiveWorkbook().GetColumnHeaderCellFromPixel(e.X, e.Y).ToString());
            }

    </BLOCKQUOTE>

    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:24 pm EST

    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Thanks so much for your time.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Your suggestion is almost perfect.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Now I can drag any node from a treeview and drop it in any row / column in the column header area.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>But please, pay attention to this:<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri></FONT></FONT></SPAN> 


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>If I do the click "outside of the sheet" (in my case in a treeview node that is in other region of the screen), and move the mouse over the sheet, the MouseMove event is fired just only when the left button of the mouse is released. Therefore the MouseMove event is not fired while I am moving the mouse over the sheet.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri></FONT></FONT></SPAN> 


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>If I do the click "inside of the sheet" (at any place), and I move the mouse over the sheet, the MouseMove event is fired continuously in every movement as expected.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri></FONT></FONT></SPAN> 


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>The problem here is that the treeview that I am using as source IS NOT within the FP SHEET, as you can see in the attached picture sample.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>I need to know the row and column while the drag and drop is in progress, because I must to show visual effects and perform another tasks, before to release the left button of the mouse.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>I repeat, the problem happen only when the drag operation starts outside the fpSpread.<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><FONT size=3><FONT face=Calibri>Could you verify why this happen?<o:p></o:p></FONT></FONT></SPAN>


    <SPAN style="mso-ansi-language:EN-US;"><o:p><FONT size=3 face=Calibri></FONT></o:p></SPAN>


    <FONT size=3 face=Calibri>Thanks in advance,</FONT>



  • Replied 8 September 2017, 2:24 pm EST

    <SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">Thanks again for your response.<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">The cellclick event is not useful to me in my situation, because I will not click the cell.<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">I am trying to drag information from a treeview and drop it in the header area. (I am building a report application).<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">So, while the drag and drop operation is in progress, I want to know what ColumnHeader.Cells(ROW?????, CEL?????) is at the pointer of the mouse in order to place the data "manually" when I release the right buttom of the mouse. (drop).<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;">Public</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> <SPAN style="COLOR:blue;">Sub</SPAN> FP_DragDrop(<SPAN style="COLOR:blue;">ByVal</SPAN> sender <SPAN style="COLOR:blue;">As</SPAN> <SPAN style="COLOR:blue;">Object</SPAN>, <SPAN style="COLOR:blue;">ByVal</SPAN> e <SPAN style="COLOR:blue;">As</SPAN> DragEventArgs) <SPAN style="COLOR:blue;">Handles</SPAN> FP.DragDrop<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;"><o:p> </o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;">Dim</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> ThePoint <SPAN style="COLOR:blue;">As</SPAN> Point = FP.PointToClient(<SPAN style="COLOR:blue;">New</SPAN> Point(e.X, e.Y))<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';COLOR:blue;FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;">Dim</SPAN><SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;"> TheRange <SPAN style="COLOR:blue;">As</SPAN> FarPoint.Win.Spread.Model.CellRange = <SPAN style="mso-spacerun:yes;"> </SPAN>FP.GetCellFromPixel(0, 0, ThePoint.X, ThePoint.Y)</SPAN><SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;"><o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Courier New';FONT-SIZE:10pt;mso-ansi-language:EN-US;mso-no-proof:yes;">FP.ActiveSheet.ColumnHeader.Cells </SPAN><SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">( ROW?????, CEL????? ) = "Data from de source"<o:p></o:p></SPAN>


    <SPAN style="FONT-FAMILY:'Arial','sans-serif';FONT-SIZE:10pt;mso-ansi-language:EN-US;">There is no way to catch the index of the row and column of the header area while the drag and drop operation is in progress?<o:p></o:p></SPAN>


    Thanks in advance,


    Luigggye 


     

  • Replied 8 September 2017, 2:24 pm EST

    Hello,

    In order to get the Header cell information, you may use Spreadview's GetColumnHeaderCellFromPixel( ) method.For example:

      Private Sub FpSpread1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FpSpread1.MouseUp
            Dim sv As FarPoint.Win.Spread.SpreadView = FpSpread1.GetRootWorkbook()
            Dim cr As FarPoint.Win.Spread.Model.CellRange
            cr = sv.GetColumnHeaderCellFromPixel(e.X, e.Y)  
            MsgBox("You are in row header " & cr.Column.ToString())
            MsgBox("You are in row header " & cr.Row.ToString())
        End Sub

    I hope it will help you.

    Thanks,

  • Replied 8 September 2017, 2:24 pm EST

    Hello,

    You may use HitTest method in order to to get to know about the  Column Header hit,

            Dim htInfo As FarPoint.Win.Spread.HitTestInformation
            Dim pt As New Point(FpSpread1.PointToClient(New Point(Control.MousePosition.X, Control.MousePosition.Y)))
            htInfo = FpSpread1.HitTest(pt.X, pt.Y)
            If Not htInfo Is Nothing Then
                If htInfo.Type = FarPoint.Win.Spread.HitTestType.ColumnHeader Then
                    Debug.WriteLine(htInfo.HeaderInfo.Column)
                End If
             
            End If

     You may use this code in DragEnter event.

     I hope it will help you.

    Thanks,

     

     

  • Replied 8 September 2017, 2:24 pm EST

    Excellent, it's works fine.


    Thanks so much. 


    <BLOCKQUOTE><div><img src="/wp-content/uploads/CS_images/icon-quote.gif"> DeepakSharma:</div><div>


    Hello,


    You may use HitTest method in order to to get to know about the  Column Header hit,


            Dim htInfo As FarPoint.Win.Spread.HitTestInformation
            Dim pt As New Point(FpSpread1.PointToClient(New Point(Control.MousePosition.X, Control.MousePosition.Y)))
            htInfo = FpSpread1.HitTest(pt.X, pt.Y)
            If Not htInfo Is Nothing Then
                If htInfo.Type = FarPoint.Win.Spread.HitTestType.ColumnHeader Then
                    Debug.WriteLine(htInfo.HeaderInfo.Column)
                End If
             
            End If


     You may use this code in DragEnter event.


     I hope it will help you.


    Thanks,


     


     

    </div></BLOCKQUOTE>
Need extra support?

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

Learn More

Forum Channels