Draw a line between 2 list boxes using drag and drop...

M

murl

Im starting on a application that will map fields from an excel file
to fields of a sql table for a very small integration project. I have
enabled drag and drop on the source listbox, and the form inbetween
the 2 listboxes so i can tell when im dragging over the form. Im stuck
on when i dragenter into the 2nd listbox, how can i figure out what
position their mouse is over, and what item is at that x and y
position? If anybody has any information on getting a listview item
and a clientpoint on the listbox, i would greatly appreciate it.

Thanks,
murl
 
B

Brian Davis

Something like this might do:

Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
For index As Integer = 0 To Me.ListBox1.Items.Count - 1
Dim r As Rectangle = Me.ListBox1.GetItemRectangle(index)
If e.Y >= r.Y AndAlso e.Y <= r.Y + r.Height Then
Me.Label1.Text = CStr(Me.ListBox1.Items(index))
Exit Sub
End If
Next

Me.Label1.Text = "none"

End Sub

This code only looks at the Y value, so it would not work if you had
multiple columns, but you could easily modify it for that. Obviously, I am
just displaying the value in a label, while you would be storing/using the
value in your code, but it should give a decent example of the method to
use. Also, the DragEventArgs will give you X and Y just like
MouseEventArgs.

You mentioned something about a ListViewItem in your post. If you use a
ListView rather than a ListBox, then you can use the GetItemAt method of the
ListView, passing a Point object.


Brian Davis
www.knowdotnet.com
 
M

Murl Brown

Ah,ok i noticed the get item at method but even think to loop through
the list of items to get it's index. I really apreciate it, that helped
me out alot, btw have you come accross any tutorials or code examples of
the steps for drawing the line from each listbox as in a field mapping
program, with redraw, etc?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top