DragDrop from one container to a diff. container.

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 :-|
LVL 9
Hawkvalley1Asked:
Who is Participating?
 
Hawkvalley1Connect With a Mentor Author Commented:
I got it, I needed to make a DragEnter and DRagDrop for the FLP control as well. And no not ASP.net.
0
 
CodeCruiserCommented:
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
 
Hawkvalley1Author Commented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
CodeCruiserCommented:
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
 
Hawkvalley1Author Commented:
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
 
CodeCruiserCommented:
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
 
Hawkvalley1Author Commented:
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
 
CodeCruiserConnect With a Mentor Commented:
Did you set the AllowDrop property of the container to True?
0
 
Hawkvalley1Author Commented:
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
 
CodeCruiserCommented:
Cant say really. Can you show some screenshot?
0
 
Hawkvalley1Author Commented:
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
 
CodeCruiserCommented:
Is the user control derived from panel?
0
 
Hawkvalley1Author Commented:
No I just added the User Control from the <add items> drop down, does it need to inherit Panel or FlowLayoutPanel rather?
0
 
Hawkvalley1Author Commented:
Will that cause a problem since there are 2 labels in the UC?
0
 
CodeCruiserConnect With a Mentor Commented:
If it is ASP.NET application then bare in mind that there is no inherent drag and drop support in ASP.NET controls.
0
 
CodeCruiserCommented:
So you did not have implemented these events already?
0
 
Hawkvalley1Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.