473,396 Members | 1,760 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,396 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
Jul 21 '05 #1
5 1817
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


Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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
Jul 21 '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...
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...
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,...
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)...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...

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.