|
-
Feb 22nd, 2007, 07:20 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Comparing Two Listviews
I have 2 Listviews, which both contain a list of names. For example :
Listview1
---------
Jon
Jim
Alan
Lee
Claire
Paul
ListView2
---------
Susan
James
Tony
Jon
Alan
What I'd like to do is compare the two listboxes, and if a name appears in both lists, I'd like to remove it from List2
I have the following code which populates the Listviews, and I assume I need to add something into the For...Next Loop, but I'm not sure what?
VB Code:
Dim aRow As DataRow
Dim X As ListViewItem = Nothing
For Each aRow In ds.Tables(0).Rows
X = New ListViewItem(aRow.Item("Name").ToString, 0)
Listview2.Items.AddRange(New ListViewItem() {X})
Next
Can anyone help please ?
-
Feb 22nd, 2007, 09:47 AM
#2
Re: [2005] Comparing Two Listviews
What you can do is to check if an item is not in listview1 then add it to listview2
VB Code:
Dim aRow As DataRow = Nothing
Dim txt As String = String.Empty
For Each aRow In ds.Tables(0).Rows
txt = aRow.Item("Name").ToString
If ListView1.FindItemWithText(txt) Is Nothing Then
ListView2.Items.Add(txt, 0)
End If
Next
-
Feb 22nd, 2007, 10:16 AM
#3
Re: [2005] Comparing Two Listviews
How are you populating your dataset in the first place? you may simply be able to avoid the duplicates by using different SQL syntax if you are pulling this data from a database. That puts the work on the database versus on the windows app, and will likely save time because you dont have to fill up 2 controls and then filter them. You simply only get back the records needed to fill the listviews.
-
Feb 23rd, 2007, 11:06 AM
#4
Thread Starter
Hyperactive Member
Re: [2005] Comparing Two Listviews
Thanks Stanav and Kleinma for your help - both are excellent suggestions.
I'll go with one of those.
Thanks.
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
|