Performing drag and drop between two datagridviews?
-
Hi I need to perform drag and drop between 2 datagridviews containing the same type of information? I want to drag and drop the entire row not just a cell value. If the user drags and drops a row from the source onto a row in the target then I want the fields to be updated please help... cant find anything online so far? Mr Oizo
-
Hi I need to perform drag and drop between 2 datagridviews containing the same type of information? I want to drag and drop the entire row not just a cell value. If the user drags and drops a row from the source onto a row in the target then I want the fields to be updated please help... cant find anything online so far? Mr Oizo
Drag and drop isn't exactly the easiest thing to understand. Newbie's to it get really confused about which side is supposed to be handling what, what Effects are, how to get the data out of the event args, what Data Formats are, how data is even represented in the operation. In your case, your doing it all inside your own app. Learn the basics of drag and drop first before you start applying it to your DGV's and posting up DataGridRows into the operation. Start with creating a ListView that is a drop target and can take files dragged to it. Drop a ListView on a form and enable it's AllowDrop property.
Private Sub ListView1\_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop If e.AllowedEffect And DragDropEffects.Copy = DragDropEffects.Copy Or \_ e.AllowedEffect And DragDropEffects.Move = DragDropEffects.Move Then Dim items As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop, True), String()) For Each item As String In items Dim lvItem As New ListViewItem(item) ListView1.Items.Add(item) Next End If End Sub
This is just the Drop side of a Drag and Drop. Once you completely understand every line of this code, you can start experimenting with starting your own Drag. Why all this step-by-step crap?? Because it's what confuses everyone who starts out. They can't keep the two sides of a Drag and Drop straight in their head, and therefore can't keep it straight in their code either.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007