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

  • Home
  • SEARCH
  • 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 9001673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:28:04+00:00 2026-06-16T00:28:04+00:00

I’ve looked and looked and can’t find an answer. I have a TreeView .

  • 0

I’ve looked and looked and can’t find an answer.

I have a TreeView. It has Drag and Drop to allow moving of Nodes within the tree.

I want to limit the drag and drop to only work within that one control, within a single instance of the application (the application itself can run more than one instance).

I’ve tried the following:

private void SubFolderTreeView_DragEnter(object sender, DragEventArgs e)
{
    TreeView source = sender as TreeView;    // also tried = (TreeView) sender;

    if (source == this.SubFolderTreeView && e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
        e.Effect = DragDropEffects.Move; // Okay, set the visual effect
    else
        e.Effect = DragDropEffects.None; // Unknown data, ignore it
}

Unfortunately, a second instance of the same application will still be able to drag from its TreeView to the first TreeView: (source == this.SubFolderTreeView) is true

I have not tested if a totally different treeview could drag to mine, though I doubt it, but the above behaviour is already a fail.

I tried some other things – comparing the form or the control’s handle also didn’t work

bool isSameForm = ((MyForm) source.TopLevelControl == this);    // still true
bool isSameHandle = (((Control)source).Handle == ((Control)this.SubFolderTreeView).Handle);     // still true

The only other things I can think of, off the top of my head, is a random number stored in the TreeView or Form (probably won’t work), and checking the absolute screen position of the control (not the best method).

I could of course stick a mutex in the application and so only allow one instance to run, but I’d rather not.

Can anyone suggest a good way of doing this?

  • 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-16T00:28:05+00:00Added an answer on June 16, 2026 at 12:28 am

    To flesh out Hans Passant’s solution (which worked perfectly, thanks Hans) for future reference and other searchers into this problem, I used the code:

    // prevents dragging from other instances of this form - thanks to Hans Passant
    private bool DragDropFromThisForm = false;
    
    private void SubFolderTreeView_ItemDrag(object sender, ItemDragEventArgs e)
    {
        // Initiate drag/drop
        DragDropFromThisForm = true;
        DoDragDrop(e.Item, DragDropEffects.Move);
        DragDropFromThisForm = false;
    }
    
    private void SubFolderTreeView_DragEnter(object sender, DragEventArgs e)
    {
        MyForm form = (MyForm) (sender as TreeView).TopLevelControl;
    
        if (form.DragDropFromThisForm && e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            e.Effect = DragDropEffects.Move; // Okay, set the visual effect
        else
            e.Effect = DragDropEffects.None; // Unknown data, ignore it
    }
    

    It may well be that DJ Kraze’s answer would also work, and perhaps be a tad more elegant, but Hans’ solution is lightweight and effective.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.