Results 1 to 5 of 5

Thread: [RESOLVED] Copying Selected ListView Items

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    79

    Resolved [RESOLVED] Copying Selected ListView Items

    Hi,

    I'm having some minor issues right now in trying to get a selected row copied over from a ListView control to another ListView control. Assuming they have the same number of columns - could someone help out? I tried searching but ran into a thread where a guy needed help getting them into a ListBox control - it wasn't helpful at all. Did a google search and came across:

    http://vbcity.com/forums/p/132841/567620.aspx

    I just don't know how I'd apply it to this current project.

    Could one of you guys code it out assuming one of my controls is called sourceListView and the second is called destinationListView? I was thinking about doing it on an ItemClick event.

    Thanks in advanced, I will add to reputation.

  2. #2
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Copying Selected ListView Items

    Here's an example for the ItemClick event.

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim i As Long
    5.    
    6.     'Here we setup the Listview. This is just an example.
    7.  
    8.     sourceListView.ColumnHeaders.Add , , "Column 1", 1500
    9.     sourceListView.ColumnHeaders.Add , , "Column 2", 1500
    10.     sourceListView.ColumnHeaders.Add , , "Column 3", 1500
    11.    
    12.     destinationListView.ColumnHeaders.Add , , "Column 1", 1500
    13.     destinationListView.ColumnHeaders.Add , , "Column 2", 1500
    14.     destinationListView.ColumnHeaders.Add , , "Column 3", 1500
    15.    
    16.     sourceListView.FullRowSelect = True
    17.     destinationListView.FullRowSelect = True
    18.    
    19.     sourceListView.View = lvwReport
    20.     destinationListView.View = lvwReport
    21.    
    22.     For i = 1 To 10
    23.         sourceListView.ListItems.Add , , "Item " & i
    24.         sourceListView.ListItems(i).SubItems(1) = "SubItem " & i
    25.         sourceListView.ListItems(i).SubItems(2) = "SubItem " & i
    26.     Next i
    27. End Sub
    28.  
    29. Private Sub sourceListView_ItemClick(ByVal Item As MSComctlLib.ListItem)
    30.     Dim i As Long
    31.    
    32.     destinationListView.ListItems.Add , , Item.Text
    33.    
    34.     For i = 1 To Item.ListSubItems.Count
    35.         destinationListView.ListItems(destinationListView.ListItems.Count).SubItems(i) = Item.SubItems(i)
    36.     Next i
    37. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    79

    Re: Copying Selected ListView Items

    Thanks, works perfectly. Rated up.

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Copying Selected ListView Items

    Please also take time to mark the thread as Resolved. You can do so by going to the Thread Tools menu which is on the right side, above your original post, and choosing Mark Thread Resolved.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    79

    Re: [RESOLVED] Copying Selected ListView Items

    Thread has been resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width