C1Treeview drag and drop file

Posted by: saidnai on 4 June 2024, 10:16 am EST

    • Post Options:
    • Link

    Posted 4 June 2024, 10:16 am EST

    Good day,

    I am searching for a VB code sample executing the drag and drop files on C1Treeview. I mean as follow:

    1) loading the Treeview is no problem (attached a small project as sample how i do). I took the

    DLLs out otherwise and cannot upload the sample.

    2) What i need is to drag and drop files on nodes and behind the parent Node-ID should be
        read and shown as a msgbox. This will allow the link between the file and the parent node.
    
    3) The same if the file moved to another Node.
    

    The picture “Screenshot.jpg” show the target.

    Thank for the support

    Said

    TreeView_Win.zip

  • Posted 5 June 2024, 6:37 am EST

    Hello Said,

    Thank you for providing the sample.

    For dragging and dropping a file in C1TreeView, you can set AllowDrop to true and handle the DragEnter and DragDrop events of C1TreeView, and to get the parent node, you can use the node.ParentCollection.Parent property as follows:

    C1TreeView1.AllowDrop = True
    AddHandler C1TreeView1.DragEnter, AddressOf C1TreeView1_DragEnter
    AddHandler C1TreeView1.DragDrop, AddressOf C1TreeView1_DargDrop
    .
    .
    .
    Private Sub C1TreeView1_DragEnter(sender As Object, e As DragEventArgs)
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.Copy
    End Sub
    
    Private Sub C1TreeView1_DargDrop(sender As Object, e As DragEventArgs)
        Dim node = C1TreeView1.GetNodeAtPoint(C1TreeView1.PointToClient(New Point(e.X, e.Y)))
        Dim data = e.Data.GetData(DataFormats.FileDrop)
        If IsNothing(data) Then Return
        node(0) = DirectCast(data, String())(0)
        MessageBox.Show($"Node val: {node(0)}{vbNewLine}NodeParent val: {node.ParentCollection?.Parent?(0)}")
    End Sub

    Please refer to the attached modified sample for implementation. (see TreeView_Win_Mod.zip)

    In the sample, we have displayed the path of the file dropped to the C1TreeView.

    If you have a different requirement, please share more details on your use case so that we can assist you accordingly.

    Regards,

    Uttkarsh.

  • Posted 7 June 2024, 6:37 am EST - Updated 7 June 2024, 6:42 am EST

    Dear Uttkarsh,

    Thanks for the support. I will explain exactly what i do and what i need:

    at the moment the documents are uploaded per drag and drop on C1Flexgrid and linked to the nodes in the system in another W.form. Whe the tree is loaded you can see the assigned document to each node as child node.

    The idea is to drag and drop the document directly on a specific node in the tree and update the table for the link behind. To achieve this i need the ID of the targeted node for the document name and the path is done in the previous sample.

    I have attached a picture to show the target. I also marked the documents in yellow.

    I do the remark for the sample: When i drop the file, the node name will be replaced with the path and document name. It will not be show as a new child of it.

    Best regards

    Said

  • Posted 10 June 2024, 7:41 am EST

    Hello Said,

    As per our understanding of your requirement:

    1. When a file is dropped on a node, you want to update that node with the file name
    2. Get the node’s ID. Here, by ID, we think you need a unique identifier for the node. For it, you can use the complete file name, as it will be unique for each file on the system.

      If you have a different implementation for ID, please elaborate.

    We have updated the sample to display the file name when dropped on a node and display its complete name in the MessageBox. Please refer to the attached modified sample. (see TreeView_Win_Mod2.zip)

    If this is not how you want to implement things, please provide us with more details so that we can assist you accordingly.

    Regards,

    Uttkarsh.

  • Posted 10 June 2024, 11:32 am EST

    Dear Uttkarsh,

    Sorry i was not clear with what i need.

    As you know, i load the tree nodes (Parents and Childs) from the database. Each record has its own ID in the table.

    When I drag and drop the document, it does not matter on wich one (Parent or Child) i need to get its ID. With it i can create a new record in the table calls “TrwDocuments”.

    Means the dragged document will be assigned to this parent or child. After writing in the table, there will be a refresh of the Treeview to show the document under its parent or child.

    So create a new record is no problem. The issue is :

    1) How to get the ID of parent or child?

    2) How to get the document name?

    3) How to get the document path?

    I have attached a sample and also create a new table “TrwDocuments” in TRW.mdb.

    Best regards

    Said

    TreeView_Win.zip

  • Posted 11 June 2024, 11:04 pm EST

    Hello Said,

    Thank you for providing more details.

    Since there is no direct way to get the ID, you can store it in the node’s Tag property during initialization and retrieve it later.

    We have updated your sample. Now, if you drop a file on the node, an entry will be added to the “TrwDocuments” table in TRW.mdb as per the file dropped.

    Please refer to the attached modified sample and let us know if it fulfils your requirements. (see TreeView_Win_Sample.zip)

    Regards,

    Uttkarsh.

  • Posted 12 June 2024, 7:25 am EST

    Dear Uttkarsh,

    I have reworked your sample function. It is working perfectly. Thanks a lot.

    Is it possible to get per right mouse click the Option: Delete on the node. It should be only for documents nodes?

    Best regards

    Said

  • Posted 13 June 2024, 8:21 am EST

    Hello Said,

    You can create a ContextMenuStrip, add a “Remove Node” button to it and assign it to the C1TreeView. After that, you can handle BeforeContextMenuShow event of the C1TreeView to cancel showing context menu if the node is not a document node.

    Please refer to the attached modified sample for implementation. (see TreeView_Win_DeleteNode.zip)

    Regards,

    Uttkarsh.

  • Posted 14 June 2024, 2:10 am EST

    Dear Uttkarsh,

    I have reworked your sample function. It is working perfectly.

    Thanks a lot.

    Best regards

    Said

Need extra support?

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

Learn More

Forum Channels