To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Feb 22nd, 2007, 07:20 AM   #1
Jonny1409
Hyperactive Member
 
Jonny1409's Avatar
 
Join Date: Mar 05
Posts: 288
Jonny1409 is on a distinguished road (10+)
Resolved [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:
  1. Dim aRow As DataRow
  2. Dim X As ListViewItem = Nothing
  3. For Each aRow In ds.Tables(0).Rows
  4.      X = New ListViewItem(aRow.Item("Name").ToString, 0)
  5.      Listview2.Items.AddRange(New ListViewItem() {X})
  6. Next

Can anyone help please ?
Jonny1409 is offline   Reply With Quote
Old Feb 22nd, 2007, 09:47 AM   #2
stanav
PowerPoster
 
stanav's Avatar
 
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 6,855
stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)
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:
  1. Dim aRow As DataRow = Nothing
  2.         Dim txt As String = String.Empty
  3.         For Each aRow In ds.Tables(0).Rows
  4.             txt = aRow.Item("Name").ToString
  5.             If ListView1.FindItemWithText(txt) Is Nothing Then
  6.                 ListView2.Items.Add(txt, 0)
  7.             End If
  8.         Next
stanav is offline   Reply With Quote
Old Feb 22nd, 2007, 10:16 AM   #3
kleinma
Moderator.NET
 
kleinma's Avatar
 
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 22,036
kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)kleinma has much to be proud of (1500+)
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.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above
PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
* If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
ZerosAndTheOne.com
-=Matt=-
kleinma is offline   Reply With Quote
Old Feb 23rd, 2007, 11:06 AM   #4
Jonny1409
Hyperactive Member
 
Jonny1409's Avatar
 
Join Date: Mar 05
Posts: 288
Jonny1409 is on a distinguished road (10+)
Re: [2005] Comparing Two Listviews

Thanks Stanav and Kleinma for your help - both are excellent suggestions.
I'll go with one of those.

Thanks.
Jonny1409 is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:19 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.