Mouse position on the Listview by Drag&Drop?

G

Guest

Hello NG,

I try to use drag and drop function between two list views. For this I found
following code:

http://msdn.microsoft.com/library/d.../en-us/dv_vstechart/html/vbtchimpdragdrop.asp

It works fine, but I have another problem. I want to create functionality
like a Windows Explorer. This means, if I select some items from list view No
1 and drag&drop this to the list view No 2, then I want to mark automatically
the item from list view No 2 under the mouse cursor (this would be like same
as if you want to copy some files to a directory in Windows Explorer. The
actually directory under mouse will be marked).

For check this event I use following function:

Private Sub ListView_DragOver(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles MyListView.DragOver

…
…

End Sub

And for get the actually item index, I use this method:
Me. MyListView.GetItemAt(e.X, e.Y).Index
So I can mark the Item under my cursor by drag&drop.
It would be good, but the event arguments e.X and e.Y returns the global
mouse position!!! So I cannot use this, because I need the relative cursor
position to the list view!

How can I get the actually list view mouse position used Drag.Over event?

Thanks
simon
 
G

Guest

Solution:

' Highlight the item under the mouse.
Private Sub List_DragOver(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles LV_Dir.DragOver
Dim this_list As ListView = DirectCast(sender, ListView)
Dim pt As Point = this_list.PointToClient(New Point(e.X, e.Y))
Dim drop_index As Integer = this_list.GetItemAt(pt.X, pt.Y).Index

this_list.SelectedItems.Clear()
this_list.Items(drop_index).Selected = True
If pt.Y < 5 Then this_list.EnsureVisible(drop_index - 1)
If pt.Y > this_list.Height - 10 Then
this_list.EnsureVisible(drop_index + 1)
End Sub
 

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