473,623 Members | 3,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

dx
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 NameObjectColle ctionBase 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 NameObjectColle ctionBase, 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

Nov 21 '05 #1
1 1569
dx,
Have you looked at System.Collecti ons.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.Binar ySearch is useful for
this). Which of course requires an Insert method.

Hope this helps
Jay

"dx" <de*********@ya hoo.com> wrote in message
news:bV******** ********@fe05.l ga...
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 NameObjectColle ctionBase 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 NameObjectColle ctionBase, 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

Nov 21 '05 #2

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

Similar topics

1
1071
by: dx | last post by:
I'd appreciate some ideas or direction with a collection issue. I need to create a custom collection that inherits ICollection, IEnumberable (need to be able to access by key, index and be able to enumerate) and this is the kicker...should be able to define the location (index) when inserting a new item (like arraylist allows.) The real challenge here is being able to specify the index or where the item will appear when enumerating thru...
5
283
by: Michel | last post by:
Please how to identify the las item of an itemcollection without to scan all the collection.
1
1081
by: dx | last post by:
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'.
0
4791
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having manually inserted a row in the table bound to the Combo box. The InsertAt Method of adding a row just does not work. Hope this helps anyone with this problem. john
2
1563
by: Yuk Tang | last post by:
I've satisfactorily got an axwebbrowser control on a form within a panel, suitably positioned and sized, and now I want to display a webpage on it. This is not normally a problem when I have the control as a uniquely named object, since I would just use the axweb.Navigate or Navigate2 method to send it to the right page. However, it's part of a controls collection, accessible only via its place in the collection.
7
5502
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the default behavior and then create an overload as IndexOf(int index, ProductSearchCriteria criteria)...
6
1872
by: Burt | last post by:
I need to create a collection of classes (or structures) can be accessed by a string key, eg MyColl("ShortName5").Name for class with key ShortName5. But it also has to be sorted by a second ordering field. Hashtable offers access by key, but is not sorted. Arraylist is sorted (the fields will come presorted from the db), but I can't access by key. SortedList can't be sorted by a field different from the key field.
0
2168
by: G | last post by:
Hello friend, I am using a textbox with in a forloop, for each time when i click a button it genarates a new textbox, so for example for first time there will be 1 textbox, i will enter some value into that textbox and i click the button which adds another textbox and i enter someother value and i go on clicking for to add a new textbox and enters some value. after creating 5 textboxes i want to know the index of the textbox, basing on...
3
5087
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages (Java). It stores character strings, and resizes itself to accommodate new strings when needed. Interface: ----------
0
8221
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8162
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8662
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5560
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4067
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2593
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1468
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.