Solved

VB.net Drag and Drop and Mouse Move

Posted on 2008-10-22
4
862 Views
Last Modified: 2010-04-21
Hi in the event  "lsvAction_DragDrop" I need to change the line that the user drags to using the following event. The problem is that it doesn't work all the time. I need to get the exact index before the DragDrop is initiated
Private Sub lsvAction_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lsvAction.MouseMove

        Dim LocalMousePosition As Point
        LocalMousePosition = Me.lsvAction.PointToClient(Cursor.Position)

        Dim x As Integer = LocalMousePosition.X
        Dim y As Integer = LocalMousePosition.Y

        Dim HoveredItem As ListViewItem = Me.lsvAction.GetItemAt(x, y)
        If HoveredItem Is Nothing Then Return

        ListIndex_on_Mousehover = HoveredItem.Index

    End Sub
0
Comment
Question by:murbro
  • 2
4 Comments
 
LVL 10

Expert Comment

by:kdwood
Comment Utility
Why not use the MouseDown event.  That way you know for sure what the index of the item is that they clicked on to drag.  For example I have an application where I'm dragging items between two ListBoxes.  I approach it as follows:

1. On the ListBox MouseDown Event:

                If Me.YourListBoxDraggedFrom.SelectedIndex <> -1 Then
                    Dim dragData As String = Me.YourListBox.SelectedItem
                    Me.YourListBox.DoDragDrop(dragData, DragDropEffects.Copy)
                End If

2. On the ListBox DragLeaveEvent:

     e.Effect = DragDropEffects.Copy

3. On the Listbox DragDropEvent

     Me.YourListboxDraggedTo.Items.Add(e.Data.GetData(GetType(String)))

Let me know if this helps.

Regards,

Keith

0
 
LVL 10

Accepted Solution

by:
kdwood earned 250 total points
Comment Utility
oops typo.... section 1 should read:

1. On the ListBox MouseDown Event:

                If Me.YourListBoxDraggedFrom.SelectedIndex <> -1 Then
                    Dim dragData As String = Me.YourListBox.SelectedItem
                    Me.YourListBoxDraggedFrom.DoDragDrop(dragData, DragDropEffects.Copy)
                End If
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 total points
Comment Utility
You should get multiple DragOver() events before the final DragDrop() event.

Try:
    Private Sub lsvAction_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lsvAction.DragOver        

        Dim HoveredItem As ListViewItem = Me.lsvAction.GetItemAt(e.X, e.Y)

        If Not IsNothing(HoveredItem) Then

            ListIndex_on_Mousehover = HoveredItem.Index

        End If

    End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
Comment Utility
thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now