Results 1 to 2 of 2

Thread: Listview - highlighting two or more instances of an item then show mutual strings

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Posts
    360

    Listview - highlighting two or more instances of an item then show mutual strings

    Lets assume I have a list of 10 items, some unique, some not. If an item appears more than once, I would like to highlight (or set the color of the cell) of ALL instances.

    Name | Friend | Address | Hobby | Mutual Friend(s)
    Bob | John |123 Big Walk Way | Games | Jill, Tony
    Jill | John |123 Big Walk Way | Blogging | Bob, Tony
    Ben | Sally |123 Big Walk Way | Coin Collecting | None
    Tony | John |123 Big Walk Way | Gardening | Bob, Jill

    All THREE of the above rows should have a blue BackColor.

    This code seems to partially be doing what I want but it's not highlighting all instances. Sometimes only two instances when there are 2+

    Lastly, I need the 5th (Mutual Friends) Column updated with a comma delimited string of friends each Name has in common.

    Code:
     For upIndex = ListView1.Items.Count - 1 To 1 Step -1
                Dim upItem = ListView1.Items(upIndex)
    
                For downIndex = 0 To upIndex - 1 Step 1
                    Dim downItem = ListView1.Items(downIndex)
    
                    If upItem.Text = downItem.Text Then
                        'ListView1.Items.Remove(upItem)
                        ListView1.Items(downItem.Index).BackColor = Color.LightBlue
                        ListView1.Items(upItem.Index).BackColor = Color.LightBlue
                        Exit For
                    End If
    
                Next
            Next

  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Listview - highlighting two or more instances of an item then show mutual strings

    This is going off memory (bit rusty) and not knowing the objects...

    essentially, you need to check each sub items for the text as well...

    Code:
    For chkCell = 0 to Listview1.Items.count -1
          Dim sCell = Listview1.Items(chkCell)
          For ALL = 0 to Listview1.items.count -1
                If Listview1.Items(chkCell) <> ListviewItems(ALL) Then
                Dim sCompare = Listview.Items(ALL)
                    For subALL = 0 to sCompare.subitems.count - 1
                       If sCell.text.toLower = sCompare.subitems(subALL).text.tolower then
                          'do stuff
                       End if
                    Next
                End If
          Next
    Next
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread 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