INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Listview - Multicolumnar cloning of multiple list items....

Listview - Multicolumnar cloning of multiple list items....

(OP)
I have two sets of code - the first a cloning I need of a list item in Drag and Drop because it allows all columns to move from ListView1 (lvInvoicingOptions) to Listview2 (lvListUnInvoiced). The second set of code works for multi-row but only drops the first column - which is non-identifying date info. Is there a way to gracefully merge these two codes so I can get my multi-columnar and multi-row drop? I am getting Object errors left and right.

CODE

Private Sub lvInvoiceOptions_ItemDrag(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.ItemDragEventArgs) Handles lvInvoiceOptions.ItemDrag
        lvi = lvInvoiceOptions.SelectedItems(0).Clone()

        ' Create a DataObject that holds the ListViewItem.
        sender.DoDragDrop(New DataObject("System.Windows.Forms.ListViewItem", lvi), DragDropEffects.Copy)
    End Sub

    Private Sub lvListUnInvoiced_DragEnter(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.DragEventArgs) Handles lvListUnInvoiced.DragEnter
        ' Check that a ListViewItem is being passed.
        If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem") Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub
    Private Sub lvListUnInvoiced_DragDrop(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.DragEventArgs) Handles lvInvoiceOptions.DragDrop, lvListUnInvoiced.DragDrop
        lvListUnInvoiced.Items.Add(lvi)
        lvInvoiceOptions.Items.Remove(lvInvoiceOptions.SelectedItems.Item(0))
    End Sub 

MSDN Multirow DragDrop

CODE

Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As _
System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag, _
ListView2.ItemDrag
    Dim myItem As ListViewItem
    Dim myItems(sender.SelectedItems.Count - 1) As ListViewItem
    Dim i As Integer = 0

     ' Loop though the SelectedItems collection for the source.
    For Each myItem In sender.SelectedItems
        ' Add the ListViewItem to the array of ListViewItems.
        myItems(i) = myItem
        i = i + 1
    Next
    ' Create a DataObject containg the array of ListViewItems.
    sender.DoDragDrop(New _
    DataObject("System.Windows.Forms.ListViewItem()", myItems), _
    DragDropEffects.Move)
End Sub

Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter, _
ListView2.DragEnter
    ' Check for the custom DataFormat ListViewItem array.
    If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem()") Then
         e.Effect = DragDropEffects.Move
    Else
        e.Effect = DragDropEffects.None
    End If
End Sub

Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, _
ListView2.DragDrop
    Dim myItem As ListViewItem
    Dim myItems() As ListViewItem = _ e.Data.GetData("System.Windows.Forms.ListViewItem()")
    Dim i As Integer = 0

    For Each myItem In myItems
        ' Add the item to the target list.
        sender.Items.Add(myItems(i).Text)
        ' Remove the item from the source list.
        If sender Is ListView1 Then
            ListView2.Items.Remove(ListView2.SelectedItems.Item(0))
        Else
            ListView1.Items.Remove(ListView1.SelectedItems.Item(0))
        End If
        i = i + 1
    Next
End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close