Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Performing drag and drop between two datagridviews?

Performing drag and drop between two datagridviews?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Oizo
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • M 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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups