470,601 Members | 1,167 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,601 developers. It's quick & easy.

Mouse position on the Listview by Drag&Drop?

Sim

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/de...mpdragdrop.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

Oct 26 '06 #1
1 5050
Sim
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
"Sim" wrote:
>
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/de...mpdragdrop.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
Oct 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by srikanth | last post: by
2 posts views Thread by Grey | last post: by
5 posts views Thread by sesar | last post: by
5 posts views Thread by murrayatuptowngallery | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.