Link to home
Start Free TrialLog in
Avatar of CASorter
CASorterFlag for United States of America

asked on

drag and drop from a datagridview to a list box

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
Avatar of SStory
SStory
Flag of United States of America image

First, I suggest on DragEnter, do a messagebox of the type data to be sure that it is what you think it is.
Avatar of CASorter

ASKER

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.
Instead of DataGridView1_MouseDown, move the code to MouseMove
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
have been withouth power for 3 days.. will try this on monday
that worked...  

thanks