Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:51:08+00:00 2026-06-15T16:51:08+00:00

I have two TreeView which are in seperate forms. treeView1 treeView2 I implemented a

  • 0

I have two TreeView which are in seperate forms.

  • treeView1
  • treeView2

I implemented a Drag and Drop functionality so that I can drag from on tree to another and it works fine with the code I found here where I have to handle 3 events.

The thing is the setup of my windows looks like this :

enter image description here

As you can see, Window2 hides my Window1 and it’s on purpose and needs to stay like this. The problem is my Drag and Drop is from Window2 to Window1 so I can’t specify a destination node. Is there a way to simply drop into a TreeView without any destination node and say create a parent node next to the other ones ?


Links die examples don’t :

private void Form1_Load(object sender, System.EventArgs e)
{
    this.treeView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView_ItemDrag);
    this.treeView2.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView_ItemDrag);
    this.treeView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeView_DragEnter);
    this.treeView2.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeView_DragEnter);
    this.treeView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeView_DragDrop);
    this.treeView2.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeView_DragDrop);   
}

private void treeView_ItemDrag(object sender,
        System.Windows.Forms.ItemDragEventArgs e)
{
    DoDragDrop(e.Item, DragDropEffects.Move);
}

private void treeView_DragEnter(object sender,
        System.Windows.Forms.DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

private void treeView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
    TreeNode NewNode;

    if(e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
    {
        Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
        TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);
            NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
        if(DestinationNode.TreeView != NewNode.TreeView)
        {     
            DestinationNode.Nodes.Add((TreeNode) NewNode.Clone());
            DestinationNode.Expand();
            //Remove Original Node
            NewNode.Remove();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:51:09+00:00Added an answer on June 15, 2026 at 4:51 pm

    Change treeview_dragdrop of both forms to the following:

       private void treeView_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            TreeNode NewNode;
    
            if(e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                NewNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
                if (!(sender as TreeView).Nodes.Contains(NewNode))//Edit: add this if you don't want to add the same one again.
                {    
                     (sender as TreeView).Nodes.Add((TreeNode) NewNode.Clone());                 
                     NewNode.Remove(); //Edit: add this if you want to remove original one.
                } 
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm populating a TreeView through a XmlDataProvider, and have already implemented Drag-and-drop functionality, so
I have two classes (MVC view model) which inherits from one abstract base class.
I have a TreeView control which displays two things: 1) Folder 2) Item Where
I have two tables user and treeview . From my registration form I wanna
Let's say we have a Windows app that has a TreeView and you can
I have two classes that I'd like to show in a treeview. In my
I have two functions that together build a treeview list on my website. It's
I have two columns say Main and Sub . (they can be of same
I have WPF treeView which has ControlTemplate which show every node of treeView consisting
Background I have a TreeView that follows the MVVM design pattern and supports multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.