Solved

drag and drop from a datagridview to a list box

Posted on 2014-01-31
6
511 Views
Last Modified: 2014-02-11
i had this working, and then it stopped ...

not sure what i did.

object is to  grab a row from a datagridview and put it into whichever list box i end up over.

DGV has 3 columns, i am only putting column 1 and 0 in the list box.

now if i try and grab a row and move it.. the datagridview1_mousedown fires  but when i move the mouse, i get a circle with a slash and when i move it over the lists box the dragenter doesnt fire
when i let go of the mosue the circle slash dissappears

i have allow drop set to true for all the listboxes.






    Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown

        DataGridView1.DoDragDrop(DataGridView1.SelectedRows, DragDropEffects.Move)

    End Sub





    Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop
        Dim rows As DataGridViewSelectedRowCollection = DirectCast(e.Data.GetData(GetType(DataGridViewSelectedRowCollection)), DataGridViewSelectedRowCollection)
        Dim Row_String As String
        For Each row As DataGridViewRow In rows
            Row_String = RTrim(LTrim(row.Cells(1).Value.ToString)) + " " + row.Cells(0).Value
            ListBox1.Items.Add(Row_String)
            DataGridView1.Rows.Remove(row)
        Next

    End Sub

    Private Sub ListBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)

        If (e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection))) Then
            e.Effect = DragDropEffects.Move
        End If


    End Sub


    Private Sub ListBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        Dim rows As DataGridViewSelectedRowCollection = DirectCast(e.Data.GetData(GetType(DataGridViewSelectedRowCollection)), DataGridViewSelectedRowCollection)
        Dim Row_String As String

        For Each row As DataGridViewRow In rows
            Row_String = RTrim(LTrim(row.Cells(1).Value.ToString)) + " " + row.Cells(0).Value
            ListBox2.Items.Add(Row_String)
            DataGridView1.Rows.Remove(row)
        Next

    End Sub

    Private Sub ListBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)

        If (e.Data.GetDataPresent(GetType(DataGridViewSelectedRowCollection))) Then
            e.Effect = DragDropEffects.Move
        End If


    End Sub
0
Comment
Question by:CASorter
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39830668
First, I suggest on DragEnter, do a messagebox of the type data to be sure that it is what you think it is.
0
 

Author Comment

by:CASorter
ID: 39832867
I have a stop in the dragenter....   it does not hit it

the circle with the line appears right after I start to move the mouse (after I left click), and stays until I let go of the mouse button.  but no dragenter events fire on any of the listboxes.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39833025
Instead of DataGridView1_MouseDown, move the code to MouseMove
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39835441
Be sure the event handlers have the Handles clause at the right side--sometimes those disappear and the event never fires because of it.

Here's an example from Microsoft MSDN (source: http://msdn.microsoft.com/en-us/library/aa289508%28v=vs.71%29.aspx)

Private MouseIsDown As Boolean = False

Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
    ' Set a flag to show that the mouse is down.
    MouseIsDown = True
End Sub

Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
    If MouseIsDown Then
        ' Initiate dragging.
        TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
    End If
    MouseIsDown = False
End Sub

Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
    ' Check the format of the data being dropped.
    If (e.Data.GetDataPresent(DataFormats.Text)) Then
        ' Display the copy cursor.
        e.Effect = DragDropEffects.Copy
    Else
        ' Display the no-drop cursor.
        e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
    ' Paste the text.
    TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub

Open in new window

0
 

Author Comment

by:CASorter
ID: 39843342
have been withouth power for 3 days.. will try this on monday
0
 

Author Closing Comment

by:CASorter
ID: 39850554
that worked...  

thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

20 Experts available now in Live!

Get 1:1 Help Now