By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Mouse position on the Listview by Drag&Drop?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.