Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

DBDivaAuto

IS-IT--Management
May 9, 2017
29
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top