Solved

DragDrop from one container to a diff. container.

Posted on 2009-04-01
17
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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