-
Apr 28th, 2014, 01:46 PM
#1
Thread Starter
Hyperactive Member
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
-
Apr 28th, 2014, 02:06 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|