need a collection that retains order and allows InsertAt(index) AND is accessible by key or index

  • Thread starter Thread starter Jay B. Harlow [MVP - Outlook]
  • Start date Start date
J

Jay B. Harlow [MVP - Outlook]

dx,
Have you looked at System.Collections.SortedList? (Wrapping SortedList in a
class similar to CollectionBase).

Alternatively your Add method can either Sort the list after you added it or
you can do an Insertion sort (find the position in the list for the new item
& insert the item at the position. ArrayList.BinarySearch is useful for
this). Which of course requires an Insert method.

Hope this helps
Jay
 
Any ideas? I can't find any examples that support this.

I'm thinking a solution may be something like inherting arraylist and
containing a hashtable.

or

Inheriting NameObjectCollectionBase and containing an arraylist to use for
looping thru in 'order'.


My current implementation display an inaccurate order, since the newly added
member is always appended to the end of the collection. Right now I'm
inheriting NameObjectCollectionBase, it seems to give meme everthing but
allowing me to InsertAt a specific location (therefore my order is wacked
when i enumerate.) The only potential solution I can think of for the
current implementation is to override the Add(), place all items in a
temporary contained collection, clear the class collection, and re-add using
some logic to add them in the appropriate order. I don't think this is a
good idea to clear the entire collection just to add a new item in an
appropriate order.

Thanks in advance for any ideas.

Stan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top