Link to home
Start Free TrialLog in
Avatar of bogdem
bogdem

asked on

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.
Avatar of jjardine
jjardine
Flag of United States of America image

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
Avatar of bogdem
bogdem

ASKER

Sorry, couldn’t make this code work.
What version of .net are you using??   2003 or 2005?
ASKER CERTIFIED SOLUTION
Avatar of jjardine
jjardine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bogdem

ASKER

Thanks a lot.