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 6914523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:21:29+00:00 2026-05-27T09:21:29+00:00

I have successfully created DragDrop functionality with user controls. Now I am trying to

  • 0

I have successfully created DragDrop functionality with user controls. Now I am trying to allow DragDrop functionality on some components such as ToolStripButton.

The base class, ToolStripItem, supports AllowDrop and the DragEnter/DragDrop events…

ToolStripButton hides these properties in the designer, but they are publicly accessable.

Originally I tried doing the following for each ToolStripButton:

button.AllowDrop = true;
button.DragEnter += new DragEventHandler(button_DragEnter);
button.DragDrop += new DragEventHandler(button_DragDrop);

However, the events were not ever firing. These buttons are contained within a MenuStrip, so I changed the MenuStrip.AllowDrop to true. Then I started getting DragEnter and DragDrop events, but the DragDrop event would fail due to a threading/invoke problem when accessing the Tag property of the ToolStripItem.

The ToolStripItems cannot be invoked upon. So I have tried invoking their container, the MenuStrip, with the same function. I am still getting a threading/invoke problem where the thread stops running as soon as I try to access the ToolStripItem.

Here is the code I’m using to retrieve the Tag information after invoke:

void button_DragDrop(object sender, DragEventArgs e)
{
    menuStrip.Invoke(new DragEventHandler(MyDragFunction), new object[] { sender, e });
}

void MyDragFunction(object sender, DragEventArgs e)
{
    int id = (int)((ToolStripButton)sender).Tag;
    // Debugging never reaches this line
    int dragId = (int)e.Data.GetData(DataFormatName, false);

    MoveItem(id, dragId);
}

Is Drag and Drop to a component like a ToolStripItem simply not possible? Or am I doing something wrong?

  • 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-05-27T09:21:30+00:00Added an answer on May 27, 2026 at 9:21 am

    Here is the code I got to work for me.

    I assign the DragDrop properties in the form constructor since they are hidden in the designer.

    foreach (object o in menuStrip.Items)
    {
        if (o is ToolStripButton)
        {
            ToolStripItem item = (ToolStripItem)o;
    
            item.AllowDrop = true;
            item.DragEnter += new DragEventHandler(item_DragEnter);
            item.DragOver += new DragEventHandler(item_DragOver);
            item.DragDrop += new DragEventHandler(item_DragDrop);
        }
    }
    
    private void item_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormatName, false))
        {
            e.Effect = DragDropEffects.Move;
        }
    }
    
    private void item_DragOver(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormatName, false))
        {
            e.Effect = DragDropEffects.Move;
        }
    }
    
    private void item_DragDrop(object sender, DragEventArgs e)
    {
        int id = (int)e.Data.GetData(DataFormatName, false);
        int category = Convert.ToInt32((sender as ToolStripButton).Tag);
    
        MyFunction(category, id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have successfully created an upload script using the API, but now I
I have successfully created an app to login user and post the tweet using
I have successfully created login with Facebook API, when user logins auth token is
I have successfully created a number of UserControls with various functionality setting the DataContext
With functionality from the RODBC package, I have successfully created an ODBC but receive
I have successfully created my own virtual path provider to load a user control
I have successfully created a disabled user in Active Directory via JNDI, but I
I have successfully created EditTexts depending on the user input in Android, and also
I have successfully created clean url for my project.. now what i need to
I have successfully created an app that reads from a bundled .plist file and

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.