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

    Hi


    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.


    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.


    My problem is that I can´t get the current ROW / COL index, while the drag operation is in progress.


    Private Sub FP_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FP.DragEnter


     


            e.Effect = DragDropEffects.Move


            


            HOW TO GET THE FP ACTIVE SHEET CELL (ROW AND COL) AT THIS MOMENT?


     


    End Sub


     


    Private Sub FP_DragMove(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FP.DragOver


     


            e.Effect = DragDropEffects.Move


     


            HOW TO GET THE FP ACTIVE SHEET CELL (ROW AND COL) AT THIS MOMENT?


     


    End Sub


    Thanks in advance,


    Luigggye

  • 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.



               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());


    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.


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


    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.



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


    Hope this will help you. Thanks.

  • Replied 8 September 2017, 2:24 pm EST

    Thanks so much for your time.



    Your suggestion is almost perfect.



    Now I can drag any node from a treeview and drop it in any row / column in the column header area.



    But please, pay attention to this:



     


    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.



     


    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.



     


    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.



    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.



    I repeat, the problem happen only when the drag operation starts outside the fpSpread.



    Could you verify why this happen?



    Thanks in advance,



  • Replied 8 September 2017, 2:24 pm EST

    Thanks again for your response.


    The cellclick event is not useful to me in my situation, because I will not click the cell.


    I am trying to drag information from a treeview and drop it in the header area. (I am building a report application).


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


    Public Sub FP_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles FP.DragDrop


     


    Dim ThePoint As Point = FP.PointToClient(New Point(e.X, e.Y))


    Dim TheRange As FarPoint.Win.Spread.Model.CellRange =  FP.GetCellFromPixel(0, 0, ThePoint.X, ThePoint.Y)


    FP.ActiveSheet.ColumnHeader.Cells ( ROW?????, CEL????? ) = "Data from de source"


    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?


    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. 


    DeepakSharma:


    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,


     


     

Need extra support?

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

Learn More

Forum Channels