CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Looping through the contents of a listview

    How can I achieve the best way of looping through the contentents of a listview control in order to 'throw' all the data row, by row, to a rich text box? (in order to print them).
    Thanx.

    Michael Vlastos
    Automation Engineer
    Company SouthGate Hellas SA
    Development Department
    Athens, Greece

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Looping through the contents of a listview

    This should do it for you - I'm copying all the details into a huge string, but you can change that :


    Dim li as ListItem
    Dim iSubItems as Integer
    Dim iCount as Integer
    Dim sOut as string
    '
    ' get the number of subitems - 1 because col 1 is the
    ' listitem text
    '
    iSubItems = ListView1.ColumnHeaders.Count - 1
    '
    sOut = ""
    for Each li In ListView1.ListItems
    sOut = sOut & "Key = " & li.Key & " Text = " & li.Text
    for iCount = 1 to iSubItems
    sOut = sOut & " SubItem(" & iCount & ") = " & li.SubItems(iCount)
    next
    sOut = sOut & vbCrLf
    next
    Debug.print sOut
    '





    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

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

Featured