From: Andrius B. on

>>>>Why not try a SortedList or a SortedDictionary? Just a thought!

Thats a good idea, I tried it, but the problem is, that I must have a
possibility to sort the Items by different key.
E.G. there are 3 ListViewItems (Text and two subitems, let's imagine that we
see Details - View with 3 columns) :

Name: ID: Town:

Item #1: AAA 333 OOO
Item #2: BBB 111 SSS
Item #3: AAA 222 EEE

So, if want to sort those items by ID, it is not difficult. I will create a
New SortedList(Of String, ListViewItem), and add all the items, specifying
the Item.Subitems(1).text as a key. The sorting will be performed as I
expect (t.i., after sort: Item2, Item3, Item1), because the "ID's" are
unique.

But if I want to sort the Items by "Name", things get worse. "Name" is not
unique. So I have to "whisper" to the SortedList, how I would like to order
items, if they have equal "Name" - then ID's schould be compared; if ID's
are also equal - compare the "Town". And how to tell that to SortedList?
SortedList has only one key, not two or three.
So, I have to combine the neccessary subitems when creating a key for
sorting by "Name"

key = Item.text & Item.Subitems(1).text & Item.Subitems(2).text.

Thats works for me (sorting is adequate), but that's the problem - keys
become quite "long". And, of course, when adding a new value to the
SortedList, as far as I know, the key of the new value is being compared
with the keys of values already in SortedList. Am I not right with the idea,
that the comparing of "long" keys takes more time than of "short" ones? And
of course it is not very "logic" to compare by all subitems' text: if the
one item's "Name" differs from the second item's Name, the Sortedlist should
not pay any attention to the ID's or Town's of the Items.


First  |  Prev  | 
Pages: 1 2 3
Prev: Help with Data Bound Controls
Next: Structure ?