VB.NET 2005 Drag and Drop item from List onto PictureBox

Hello, Experts!
Let say I have few PictureBoxes, and one ListBox, I want to be able drag and drop one element from ListBox onto PictureBox, on Drop event I want to see the MsgBox
With information what Item I just dropped and on what control I did it

Any help greatly appreciated.
bogdemAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jjardineCommented:
The first thing I would do is set up a method to handle the drop event on the Picture Boxes Like this:

Public Sub PictureBox_DragDrop(sender as Object, e as System.Windows.Forms.DragEventArgs)

End Sub

After creating the method I would add handlers for all of the picture boxes to be handled by this method.  Maybe do this in the Form_Load event.Ex.

AddHandler PictureBox1.DragDrop, AddressOf PictureBox_DragDrop
AddHandler PictureBox2.DragDrop, AddressOf PictureBox_DragDrop

Don't forget to set each picture box's AllowDrop property to True

On MouseDown of the Listbox you want to capture the information you want to pass to your picturebox.  This could be a reference to the listbox object or some other custom object you create to capture the information you want to send.   an example of passing the listbox would be something like this  coded in the ListBox_mouseDown Event.

listbox1.doDragDrop(listbox1,DragDropEffects.All)

Then in the PictureBox_DragDrop method first listed in this example  you could add the following code:

MessageBox.Show(DirectCast(Sender,PictureBox).Name & " is sending: " & DirectCast(e.Data,ListBox).SelectedItem)

I hope this helps get you started on working with this.  This is just a generic example of how to complete the drag drop and get general information.  You can get many other fields from the objects passed.
jjardine
0
bogdemAuthor Commented:
Sorry, couldn’t make this code work.
0
jjardineCommented:
What version of .net are you using??   2003 or 2005?
0
jjardineCommented:
I just did this sample code in 2005   and here are the results..  I added 2 picture boxes to the form and a listbox.  the listbox contains 2 items (Hello, Goodbye).   Then here is the code for when I drag an element from the listbox to the picturebox.  

  Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    PictureBox1.AllowDrop = True
    PictureBox2.AllowDrop = True

    AddHandler PictureBox1.DragDrop, AddressOf PictureBox_DragDrop
    AddHandler PictureBox2.DragDrop, AddressOf PictureBox_DragDrop

    AddHandler PictureBox1.DragEnter, AddressOf PictureBox_DragEnter
    AddHandler PictureBox2.DragEnter, AddressOf PictureBox_DragEnter
  End Sub

  Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
    ListBox1.DoDragDrop(ListBox1, DragDropEffects.Copy)
  End Sub

  Private Sub PictureBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
    MessageBox.Show(DirectCast(sender, PictureBox).Name & " received this data: " & DirectCast(e.Data.GetData(GetType(ListBox)), ListBox).SelectedItem)

  End Sub


  Private Sub PictureBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
    e.Effect = DragDropEffects.Copy
  End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bogdemAuthor Commented:
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.