471,853 Members | 839 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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

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
Nov 20 '05 #1
2 3883
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

"murl" <mu**@cbsmemphis.com> wrote in message
news:a1**************************@posting.google.c om...
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

Nov 20 '05 #2
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?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dwayne Gaddy | last post: by
3 posts views Thread by simon_s_li | last post: by
2 posts views Thread by SamSpade | last post: by
5 posts views Thread by Brian Henry | last post: by
reply views Thread by Carl Gilbert | last post: by
1 post views Thread by Alan T | last post: by
5 posts views Thread by =?Utf-8?B?UGFycm90?= | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.