Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox 3 Alike Values

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
I am doing a few comparisons among listboxes but i am trying to figure out how to find 3 alike items in a listbox, any clues?

Thanks.
 
I got it but id still like to see the way you guys would do it.
 
Describe - "alike"

Do they have the same text value? same tag? are they supposed to be the same GUI Item in different views?
 
1. Extract items from textbox and put in ArrayList
2. Sort the ArrayList
3. Loop thru the ArrayList looking for repeating entries.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Chip's method will work quite well if there's only 1 text value in the field. If you have multiple columns (like in a listview) then you will want to loop through each item, and each item's subitems to check for a match.

A simple sort of a ListView and a nested for loop would take care of this nicely.
 
If I need to search a list then when the values are put into the list I also put them into an array then I just search the array, if the search is for text (and unordered) I use the Binary tree, if it is numeric (and ordered) I use binary search, unless the list will always be small then I just do linear search; we shouldn’t forget that binary searches will always find quicker than linear,

Age is a consequence of experience
 
If you have multiple columns (like in a listview) then you will want to loop through each item, and each item's subitems to check for a match.

Actually, I seldom insert a simple string value or set of strings into a list or listview. I usually insert a full object, and create a helper object(s) that implements IComparer for sorting.

Inserting the full object works because the datatype of the value on these controls is "object", so I can insert anything I like. This works well when you have a Name and Id column from a database. You override ToString on your object so that the control displays your Name correctly. And when your user selects an item from the list, you've got the full list already, with no need to perform additional lookups to get the Id.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top