473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to Check for Dups in ListView?

The following code is how I check for duplicates in a List box. This is
simple enough as there is only one column of stuff to check.

' Check for Duplicates
' Search listbox (from last to first)
For cntr = lbDwgList.Items.Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If lbDwgList.Items(cntr) = lbDwgList.Items(cntr - 1) Then _
lbDwgList.Items.RemoveAt(cntr)
Next

But I've a ListView (2 columns) that I want to check for duplicates. Having 2
columns is not the issue as I can check for a string of Col1+Col2.

But like my Listbox example, I want to check Last Item to First Item (bottom
to top). Both my ListBox and ListViews are sorted Ascending.

In a ListView, how do I do a reverse check (never having done it before).

The following of course does not work (because it doesn't search last to
first). And it returns an Error anyways. (:

' Check for Duplicates
i = lvModDwgs.Items.Count
For Each LItem In lvModDwgs.Items
' If next item is a duplicate -> Remove It
If LItem.SubItems(i).ToString = LItem.SubItems(i + 1).ToString Then _
lvModDwgs.Items.RemoveAt(i)
i = i + 1
Next

Anyone have any suggestions?

Regards,

Bruce
Nov 20 '05 #1
5 2839
If you are retrieving the names from a database, the best way is to
use a SELECT DISTINCT when populating the listbox.

--mary

On Thu, 01 Jul 2004 17:56:45 GMT, Mr. B <Us**@NoWhere.com> wrote:
The following code is how I check for duplicates in a List box. This is
simple enough as there is only one column of stuff to check.

' Check for Duplicates
' Search listbox (from last to first)
For cntr = lbDwgList.Items.Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If lbDwgList.Items(cntr) = lbDwgList.Items(cntr - 1) Then _
lbDwgList.Items.RemoveAt(cntr)
Next

But I've a ListView (2 columns) that I want to check for duplicates. Having 2
columns is not the issue as I can check for a string of Col1+Col2.

But like my Listbox example, I want to check Last Item to First Item (bottom
to top). Both my ListBox and ListViews are sorted Ascending.

In a ListView, how do I do a reverse check (never having done it before).

The following of course does not work (because it doesn't search last to
first). And it returns an Error anyways. (:

' Check for Duplicates
i = lvModDwgs.Items.Count
For Each LItem In lvModDwgs.Items
' If next item is a duplicate -> Remove It
If LItem.SubItems(i).ToString = LItem.SubItems(i + 1).ToString Then _
lvModDwgs.Items.RemoveAt(i)
i = i + 1
Next

Anyone have any suggestions?

Regards,

Bruce


Nov 20 '05 #2
With Deft Fingers, Mary Chipman <mc***@online.microsoft.com> wrote:
If you are retrieving the names from a database, the best way is to
use a SELECT DISTINCT when populating the listbox.


Ah... sorry... I 'should' have mentioned that I'm not using a Data Base (:

What happens is that I initially select files (DWG files)... then on the 2nd
column I have names of Layout Tabs for each DWG file (there can be more than
one Tab per DWG). The application allows a user to increase the number of
Tabs per DWG file.

In my ADD tab logic, I give it a name of "Layout#" where # is a sequential
number (1, 2, 3, etc). So if a User has Layout1 and Layout2, and either adds
more Layouts or renames a Layout to an existing Layout name, I want to delete
the duplicates.

Regards,

Bruce
Nov 20 '05 #3
I'd suggest putting all the data in your listviews into an ArrayList() or
other Array based class. That way you can sort and filter through the array
quickly and more reliably (you can remove items from an array at any time -
unlike with a listview). Then simply dump the new array data back to the
listview.
_________________________________
The Grim Reaper

"Mr. B" <Us**@NoWhere.com> wrote in message
news:t9********************************@4ax.com...
With Deft Fingers, Mary Chipman <mc***@online.microsoft.com> wrote:
If you are retrieving the names from a database, the best way is to
use a SELECT DISTINCT when populating the listbox.
Ah... sorry... I 'should' have mentioned that I'm not using a Data Base (:

What happens is that I initially select files (DWG files)... then on the

2nd column I have names of Layout Tabs for each DWG file (there can be more than one Tab per DWG). The application allows a user to increase the number of
Tabs per DWG file.

In my ADD tab logic, I give it a name of "Layout#" where # is a sequential
number (1, 2, 3, etc). So if a User has Layout1 and Layout2, and either adds more Layouts or renames a Layout to an existing Layout name, I want to delete the duplicates.

Regards,

Bruce

Nov 20 '05 #4
With Deft Fingers, "The Grim Reaper" <gr*********@btopenworld.com> wrote:
I'd suggest putting all the data in your listviews into an ArrayList() or
other Array based class. That way you can sort and filter through the array
quickly and more reliably (you can remove items from an array at any time -
unlike with a listview). Then simply dump the new array data back to the
listview.


yeah... I kind of thought that was something like I'd have to do... just was
hoping there was an easier way.

Regards,

Bruce
Nov 20 '05 #5
With Deft Fingers, "slaprade" <sl******@discussions.microsoft.com> wrote:
I have had similar issues removing duplicates fro 120K items. I used hashtables. The hashtable uses a key/value pair. do something like this
Public MyHashtable as new hashtable
....
MyHashtable.item(keyname) += 1


Interesting! I've never used Hashtables (now Hash is another thing <grin>)...

Thanks muchly... I'll play with this (probably better than dumping my stuff in
a Listbox... then back to an array.

Regards,

Bruce
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sandra | last post by:
I have a form with a list view control that has the checkboxes property set to true. This provides checkboxes as the first column in the listview. When a listviewitem is checked another form is...
6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
5
by: Mr. B | last post by:
The following code is how I check for duplicates in a List box. This is simple enough as there is only one column of stuff to check. ' Check for Duplicates ' Search listbox (from last to first)...
1
by: KEVIN97810 | last post by:
Hello to all, I read data from SQL and populate a table. Howerver, there are dups that I need to prevent into my table. The dups only are in these two fields. How do you prevent this in the...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
2
by: Just Me | last post by:
I've been checking the doc for the combobox to see it there is some way I can set it up to be sorted (I found that) and to have no duplicate entries. I don't see any way to avoid dups unless...
3
by: | last post by:
Hello, I have a ListView control in Details view. When an item is un-checked, I want to change the ForeColor. The only way I have found to do this is to loop through all the items of the...
0
by: princego1 | last post by:
I 've got a table ,and I want to check for a unique column ,so that there is no dups in my mysql. So how is it done using jdbc ? This is my part code / Create PreparedStatement object String...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.