copy selected listview to listbox-VBForums
Results 1 to 8 of 8

Thread: copy selected listview to listbox

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,186

    copy selected listview to listbox

    How can i copy all the selected items in a multiselect listview to a listbox
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,664

    Re: copy selected listview to listbox

    This seems to work, puts a comma between the items.

    edit: fix
    Code:
         
        Dim x As Integer, y As Integer
        Dim l$
    
        For x = 1 To ListView1.ListItems.Count
            If ListView1.ListItems.Item(x).Selected = True Then
                l$ = l$ & ListView1.ListItems.Item(x).Text & ","
                
                For y = 1 To ListView1.ListItems.Item(x).ListSubItems.Count
                    l$ = l$ & ListView1.ListItems.Item(x).SubItems(y) & ","
                Next y
                List1.AddItem Mid$(l$, 1, Len(l$) - 1)  ' removes last comma
            End If
            
        l$ = ""
        Next x

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,186

    Re: copy selected listview to listbox

    Quote Originally Posted by Edgemeal
    This seems to work, puts a comma between the items.

    edit: fix
    Code:
         
        Dim x As Integer, y As Integer
        Dim l$
    
        For x = 1 To ListView1.ListItems.Count
            If ListView1.ListItems.Item(x).Selected = True Then
                l$ = l$ & ListView1.ListItems.Item(x).Text & ","
                
                For y = 1 To ListView1.ListItems.Item(x).ListSubItems.Count
                    l$ = l$ & ListView1.ListItems.Item(x).SubItems(y) & ","
                Next y
                List1.AddItem Mid$(l$, 1, Len(l$) - 1)  ' removes last comma
            End If
            
        l$ = ""
        Next x
    Thanks that works
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,664

    Re: copy selected listview to listbox

    l$ = l$ & ListView1.ListItems.Item(x).Text & ","
    should just be,
    l$ = ListView1.ListItems.Item(x).Text & ","
    since theres nothing in L$ yet anyway.

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: copy selected listview to listbox

    Quote Originally Posted by isnoend07
    How can i copy all the selected items in a multiselect listview to a listbox
    Why would you want to do this? If you have multiple columns, the ListView is the perfect control. A listbox does not have the column manipulation available in a Listview.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,186

    Re: copy selected listview to listbox

    Quote Originally Posted by Hack
    Why would you want to do this? If you have multiple columns, the ListView is the perfect control. A listbox does not have the column manipulation available in a Listview.
    Maybe you know a better way.
    I send emails with attachments. The user can open his wab file in windows and fill a list view with icons. They can select items then clicking buttons fills 3 listboxs To, Cc and Bcc for email recipients. Like outlook does. Do you know a better way?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: copy selected listview to listbox

    Instead of 3 listboxs why one one additional ListView with three columns?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  8. #8

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,186

    Re: copy selected listview to listbox

    Quote Originally Posted by Hack
    Instead of 3 listboxs why one one additional ListView with three columns?
    That would probably work for someone who is experienced at using a listview, but i got listboxs dialed in. As items may need to be removed
    from the lisboxs(removeitem) and the transfered to the fields in the email program, seperated by (";") all this will be easy using listboxs. if fact i would not even use the listView if i could put icons into a listbox
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.