Solved

DragDrop from one container to a diff. container.

Posted on 2009-04-01
17
244 Views
Last Modified: 2013-12-26
Hi all,
Working on a user control(UC) that are created at runtime, one UC for each DataRow and has a flowLayoutPanel that is populated with buttons based on the items in that DataRow - this part I got working. My question is how can I drag and drop the button into a diff. UC? I have done some control dragging,  but in the same container. I imagine there is something to do with control.remove and control.add while dragging.
Thanks...

Come on you know I am always doing something weird, give a brother some help :-|
0
Comment
Question by:Hawkvalley1
  • 9
  • 8
17 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Yes you need to remove the control from the source container and add it to the target container. But also consider what would happen if user drags and drops within the same container.
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Sure, but how do I remove it without losing it. Removing a control is like deleting it. If the control is duplicated then removed from a container, it would not bother me if they drop it in the same one - maybe they changed there mind. Just not sure not sure about setting this up.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
So you dont want it to be removed from the source container? The use the Clone method of the control and do not remove from the controls collection.
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Sorry, if it's location/container changes - yes it should be removed. I am just not worried if it is placed back in the same container - like they started to move the wrong object.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
If it is dropped in the same container then just dont take any action. If its only drag from containA and drop onto ContainerB then set the AllowDrop property of containerA to False. If its bothways then you would need to check whether its dragged and dropped from same container or not.
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
I'm getting close, this works 'cept it will only recognize the edge on the UC as a place to drop the button, I want it to be able to drop the item when the cursor is positioned anywhere over the FLP which is in the UC. <below> Unit is the user control. I'm just too close to the project now. I now it's right under my nose. :p)

Come on this should be an easy 500 now :-)

  Private Sub MyMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)

        DoDragDrop(New myObject(sender), DragDropEffects.Move)

    End Sub
 

    Private Sub UC_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs)

        If e.Data.GetDataPresent("myObject") Then

            e.Effect = DragDropEffects.All

        End If

    End Sub

    Private Sub UC_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)

        If e.Data.GetDataPresent("myObject") Then

            Dim u As Unit = CType(sender, Unit)

            Dim btn As Button = CType(e.Data.GetData("myObject"), Button)

            btn.Location = u.FlowLayoutPanel1.PointToClient(New Point(e.X, e.Y))

            u.FlowLayoutPanel1.Controls.Add(btn)

        End If

    End Sub

Open in new window

0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 75 total points
Comment Utility
Did you set the AllowDrop property of the container to True?
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Yes, it's not like it won't drop, it just does not recognize the FLP(area/bounds/rectangle) as a place to drop the button. Just the edge on the UC, the FLP fits top to bottom with a label on each side - long skinny control.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Cant say really. Can you show some screenshot?
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Well it wont let me, <prt sc > during the Drag, here is pic of the UC with the FLP selected, I get the Circle with the diagonal line until I get to the edge of the control.

Unit.jpg
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Is the user control derived from panel?
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
No I just added the User Control from the <add items> drop down, does it need to inherit Panel or FlowLayoutPanel rather?
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Will that cause a problem since there are 2 labels in the UC?
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 75 total points
Comment Utility
If it is ASP.NET application then bare in mind that there is no inherent drag and drop support in ASP.NET controls.
0
 
LVL 9

Accepted Solution

by:
Hawkvalley1 earned 0 total points
Comment Utility
I got it, I needed to make a DragEnter and DRagDrop for the FLP control as well. And no not ASP.net.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
So you did not have implemented these events already?
0
 
LVL 9

Author Comment

by:Hawkvalley1
Comment Utility
Well no this is a new thing for me, so just learning, I not as smart as you think I am. I am always up for a new challenge, and usually good at getting most of the stuff on my own, but this was messing with my brain initially. But thanks for being there.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now