Dragging from ListBox to canvas

Hi All

Trying to get this working from the docs but I’m obviously missing something (code below). I drag from the list row and get a nice little rectangle as expected, drag it over the canvas … but when I drop, it simply bounces back to the ListBox *using a little animation, which is nice :slight_smile: but, obviously, that’s not quite what I was after.

Another connected problem is that I’m sending the MousePosition(X) data (via a var) to a label so the user has a better idea where they’re dropping the object but it won’t update during drag. Updates fine on MouseMove but as soon as that left button is down it opts out.

Can anyone please tell me what I’m missing? Thank you.

 ListBox1
	DragRow Event

Var p As Picture = Self.BitmapForCaching(colWidth, 24)
p.Graphics.DrawingColor = &cffffff
p.Graphics.FillRectangle(mCurrentColumn, 24, colWidth, 24)

drag.DragPicture = p
drag.Text = txt

Return True

	end DragRow Event

Canvas1
	open event

Me.AcceptPictureDrop
Me.AcceptTextDrop
Me.AcceptRawDataDrop("????")

	end open event

	MouseUp Event
// Update mouse position and store it in MousePosition Property 
MousePosition = New Point(x, y)

// refresh, without erasing the background
Me.Refresh(False)
	end MouseUp Event

	paint event
If DropPic Is Nil Then Return
g.DrawPicture(DropPic, 0, 0, g.Width, g.Height, 0, 0, DropPic.Width, DropPic.Height)
	end paint event

	MouseMove event

// Store mouse position as MousePosition Property
MousePosition = New Point(x, y)
// refresh, without erasing the background
Me.Refresh(False)

	end MouseMove Event

	MouseDown Event

Return True

	end MouseDown Event

	DragOver Event

Return True

	end DragOver Event

You need to handle the Canvas.DropObject event to detect the drop and then do whatever it is you need to do with the dropped data to populate DropPic.

Update the position in MouseMove and also in MouseDrag.

Thanks Andrew. I am doing that but I believe the problem is that the ListBox isn’t “handing over” the drag event to the Canvas - indicated (if I’m right) by the fact the MouseDrag event in the Canvas doesn’t update the label if the mouse drag begins in (mouse down in) the ListBox but, if I begin the drag inside the Canvas, it does.

I must admit I’m finding the doc pages on MouseExit and MouseEnter quite confusing.