Solved

DragDrop from one container to a diff. container.

Posted on 2009-04-01
17
247 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
ID: 24047618
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
ID: 24049277
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
ID: 24049372
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 9

Author Comment

by:Hawkvalley1
ID: 24049409
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
ID: 24049440
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
ID: 24063898
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
ID: 24064017
Did you set the AllowDrop property of the container to True?
0
 
LVL 9

Author Comment

by:Hawkvalley1
ID: 24064373
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
 
LVL 83

Expert Comment

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

Author Comment

by:Hawkvalley1
ID: 24064493
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
ID: 24064523
Is the user control derived from panel?
0
 
LVL 9

Author Comment

by:Hawkvalley1
ID: 24064572
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
ID: 24064611
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
ID: 24064706
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
ID: 24065024
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
ID: 24065064
So you did not have implemented these events already?
0
 
LVL 9

Author Comment

by:Hawkvalley1
ID: 24065443
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 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

15 Experts available now in Live!

Get 1:1 Help Now