Results 1 to 3 of 3

Thread: How can I copy a whole listview row into a string?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    8

    How can I copy a whole listview row into a string?

    I have a listbox and a button event that responds to a selection.

    Is there a way to get the whole item row (including subitems) and copy it into a string? For example:

    engagement = ListView1.SelectedItems(0).Text

    that code does exactly what I want but only gets the main item and none of the subitems in my row.

    'My Items code


    Dim item1 As New ListViewItem(session(0), 0)
    item1.SubItems.Add(session(1))
    item1.SubItems.Add(session(2))
    item1.SubItems.Add(session(3))
    item1.SubItems.Add(session(4))

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How can I copy a whole listview row into a string?

    The item has a SubItems property, which is the same collection you're adding the subitems to. Each subitem in that collection has a Text property, which contains the text displayed on-screen. You can get each of those Text properties and join them together into a single string. There are various ways you can do that. The first that comes to mind is a For or For Each loop. Try implementing a loop yourself and see what you can come up with. Note that the first subitem contains the same data as the item itself, so you don't have to treat the first column differently.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    8

    Re: How can I copy a whole listview row into a string?

    Thanks so much. I did not know about that property. I actually did not need to write them into one string, they suited me individually.

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