Solved

drag and drop from a datagridview to a list box

Posted on 2014-01-31
6
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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