473,387 Members | 1,542 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,387 software developers and data experts.

Custom Collections

Hello!

I defined a custom collection class that inherits from CollectionBase, it
works fine...

Now, I would like to add each item an ID property, so I could access items
in the collection by ID. What I need is a sample how I can generate unique
ID each time when a new Item is added to the collection?

Thanks!

James
Nov 21 '05 #1
3 995
James T. wrote:
Now, I would like to add each item an ID property, so I could access
items in the collection by ID. What I need is a sample how I can
generate unique ID each time when a new Item is added to the
collection?


The way I approached this is to use actual values from within the collected
objects to provide IDs.

If I'm collecting users, I'll use the username as the identifier. This has
to be unique as each user has a unique username.

I then get my Item property to scan through the collection looking for the
user with the supplied username. If it finds it then the user is returned,
if no user is located then Nothing is returned. This also gives me a really
easy 'Exists' type function, because if Item returns Nothing then the item
doesn't exist within the collection.

It also has the advantage of dynamically updating the item keys if the
properties of the objects change. If I modify an object's Username property,
the Item key will automatically be updated with it (as they are both the
same value).

This may or may not be practical depending on what type of object you are
collecting, but worth thinking about.

--

(O)enone
Nov 21 '05 #2
James,

Are you sure that you cannot use a GUID

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
Nov 21 '05 #3
Thank you for good suggestion...

James
Now, I would like to add each item an ID property, so I could access
items in the collection by ID. What I need is a sample how I can
generate unique ID each time when a new Item is added to the
collection?


The way I approached this is to use actual values from within the
collected objects to provide IDs.

If I'm collecting users, I'll use the username as the identifier. This has
to be unique as each user has a unique username.

I then get my Item property to scan through the collection looking for the
user with the supplied username. If it finds it then the user is returned,
if no user is located then Nothing is returned. This also gives me a
really easy 'Exists' type function, because if Item returns Nothing then
the item doesn't exist within the collection.

It also has the advantage of dynamically updating the item keys if the
properties of the objects change. If I modify an object's Username
property, the Item key will automatically be updated with it (as they are
both the same value).

This may or may not be practical depending on what type of object you are
collecting, but worth thinking about.

--

(O)enone

Nov 21 '05 #4

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

Similar topics

9
by: craig | last post by:
Assume that you would like to create a custom collection class that is: 1. Strongly-typed (only holds Customer objects) 2. Read-only (user cannot add Customer objects) 3. Able to be bound to...
3
by: JimGreen | last post by:
We are designing a WinForm application ( three tiered) There is a debate in our group as to whether we should pass datasets or our custom collections from business layer to the user interface...
0
by: Jordan Bowness | last post by:
I make a similar post in another newsgroup, but this example is simplified somewhat. I have a component (cmpMyComponent) with 2 properties. The 1st property is a string value (Description) and...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
4
by: John Dalberg | last post by:
I noticed the starterkits timetracker & issue tracker load data from a database into custom collections (arraylists) which bind to a datagrid. What are the advantages of using custom collections...
9
by: Greger | last post by:
Hi, I am building an architecture that passes my custom objects to and from webservices. (Our internal architecture requires me to use webservices to any suggestion to use other remoting...
0
by: Rajesh | last post by:
I am trying to use a simple custom type for saving the profile information of a user. The custom class inherits from the Hashtable. I am serializing the type as "Binary" in the provider sections of...
0
by: w31chang | last post by:
Hi, I create custom entity objects, a custom collections for the entity objects and a custom object that acts like a collection of the custom entity collections which I called EntitySet Object. The...
4
balabaster
by: balabaster | last post by:
Okay, I decided that I needed to understand the whole custom configuration file bits and so I've spent some time playing around with it. It seems (in the most) relatively straight forward. However,...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...

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.