473,659 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a custom collection

Hello guys, how are you?

I implemented a class called MyDictionary that inherits from DictionaryBase.

The thing is that my class, cannot handle a duplicate value in the "keys"

Like;

Dim md as New MyDictionary

md.add("Mike", Object1)

md.add("Mike", Object2)

This will generate an error during compilation, because I cannot add Mike
two times to the collection, we all know that.

I need to come up with something (like a custom made collection or
structure) that allow me to do this.

I need a key (string type, can be duplicate) and a value (object type, like
an instance of another class).

Could you please help me on this, any example will be highly appreciated!

Mike
Jan 10 '06 #1
6 2700
Hi Mike,
Dim md as New MyDictionary
md.add("Mike", Object1)
md.add("Mike", Object2)
This will generate an error during compilation, because I cannot add Mike
two times to the collection, we all know that.
I suppose that you mean at run-time not a compile-time...
I need a key (string type, can be duplicate) and a value


Dictionaries use keys and keys, by definition, can not be duplicated.
Otherwise, when you try to retrieve an item by key, which one of the
duplicates you would return?

Maybe you would have to use a dictionary whose objects are collections
(allowing duplicates)...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio 2005, Visual Studio .NET,
VB6, VB5 and VBA
You can code, design and document much faster in VB.NET, C#, C++ or VJ#
Free resources for add-in developers:
http://www.mztools.com

Jan 10 '06 #2
| I implemented a class called MyDictionary that inherits from
DictionaryBase.
| The thing is that my class, cannot handle a duplicate value in the "keys"

Have you tried inheriting from
System.Collecti ons.Specialized .NameValueColle ction?

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

Unfortunately it wants strings & not objects.

You could code your Add such that if you are adding a duplicate that it
changes that entry to a list and adds the duplicates to the list.
Unfortunately this complicates the indexer's & enumerators as sometimes you
are returning a single object, sometimes multiple objects.

Have you considered defining MyDictionary to be a dictionary of an array of
your objects? Where each key holds an array (ArrayList?) of one or more
objects?
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Mike" <mi**@hitnext.c om> wrote in message
news:OF******** ******@tk2msftn gp13.phx.gbl...
| Hello guys, how are you?
|
|
|
| I implemented a class called MyDictionary that inherits from
DictionaryBase.
|
| The thing is that my class, cannot handle a duplicate value in the "keys"
|
|
|
| Like;
|
|
|
| Dim md as New MyDictionary
|
| md.add("Mike", Object1)
|
| md.add("Mike", Object2)
|
|
|
| This will generate an error during compilation, because I cannot add Mike
| two times to the collection, we all know that.
|
| I need to come up with something (like a custom made collection or
| structure) that allow me to do this.
|
| I need a key (string type, can be duplicate) and a value (object type,
like
| an instance of another class).
|
|
|
| Could you please help me on this, any example will be highly appreciated!
|
|
|
| Mike
|
|
Jan 10 '06 #3
Thanks guys, i may try you suggestion.
"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in
message news:uQ******** ******@TK2MSFTN GP12.phx.gbl...
| I implemented a class called MyDictionary that inherits from
DictionaryBase.
| The thing is that my class, cannot handle a duplicate value in the
"keys"

Have you tried inheriting from
System.Collecti ons.Specialized .NameValueColle ction?

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

Unfortunately it wants strings & not objects.

You could code your Add such that if you are adding a duplicate that it
changes that entry to a list and adds the duplicates to the list.
Unfortunately this complicates the indexer's & enumerators as sometimes
you
are returning a single object, sometimes multiple objects.

Have you considered defining MyDictionary to be a dictionary of an array
of
your objects? Where each key holds an array (ArrayList?) of one or more
objects?
--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Mike" <mi**@hitnext.c om> wrote in message
news:OF******** ******@tk2msftn gp13.phx.gbl...
| Hello guys, how are you?
|
|
|
| I implemented a class called MyDictionary that inherits from
DictionaryBase.
|
| The thing is that my class, cannot handle a duplicate value in the
"keys"
|
|
|
| Like;
|
|
|
| Dim md as New MyDictionary
|
| md.add("Mike", Object1)
|
| md.add("Mike", Object2)
|
|
|
| This will generate an error during compilation, because I cannot add
Mike
| two times to the collection, we all know that.
|
| I need to come up with something (like a custom made collection or
| structure) that allow me to do this.
|
| I need a key (string type, can be duplicate) and a value (object type,
like
| an instance of another class).
|
|
|
| Could you please help me on this, any example will be highly
appreciated!
|
|
|
| Mike
|
|

Jan 10 '06 #4
I agree with the other responses that a dictionary may not be what you want.
I would typically solve this using a class that inherits from CollectionBase
or ReadOnlyCollect ionBase (depending on the business needs). Then in my
custom Objects, add a Key property and an ID property. The ID property would
expose a GUID assigned by the BO to allow for unique searching for the
purposes of the Item and Remove methods of the collection. This will allow
you to bind to the "Key" property and have multiple objects with the same
"Key" (the ID will be different however).

Jim

"Mike" <mi**@hitnext.c om> wrote in message
news:OF******** ******@tk2msftn gp13.phx.gbl...
I implemented a class called MyDictionary that inherits from
DictionaryBase.

The thing is that my class, cannot handle a duplicate value in the "keys"

Jan 10 '06 #5
Hi jim!

what do you mean by;
Then in my custom Objects, add a Key property and an ID property

Whats a custom object for you, a class with a key, ID and value memebers?

Thanks

"Jim Wooley" <jw******@bells outh.net> wrote in message
news:eI******** *****@TK2MSFTNG P12.phx.gbl...I agree with the other responses that a dictionary may not be what you
want. I would typically solve this using a class that inherits from
CollectionBa se or ReadOnlyCollect ionBase (depending on the business needs).
Then in my custom Objects, add a Key property and an ID property. The ID
property would expose a GUID assigned by the BO to allow for unique
searching for the purposes of the Item and Remove methods of the
collection. This will allow you to bind to the "Key" property and have
multiple objects with the same "Key" (the ID will be different however).

Jim

"Mike" <mi**@hitnext.c om> wrote in message
news:OF******** ******@tk2msftn gp13.phx.gbl...
I implemented a class called MyDictionary that inherits from
DictionaryBase.

The thing is that my class, cannot handle a duplicate value in the "keys"


Jan 10 '06 #6
Mike,

I did not try it, however I got the idea that it was worth a try to use the
sortedlist and to switch your key and your item.

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

Just to try

Cor
Jan 11 '06 #7

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

Similar topics

3
6995
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the XmlSerializer will only serialize the collection items - with the default root as ArrayofMyItems etc. My custom collection class has some additional public properties that I would like to include in the serialization above the items element array (in
0
4063
by: panik | last post by:
Hi, I have a custom collection that implements CollectionBase. The collection is called Sensors and contains a list of Sensor objects. There is the usual index using an integer (Sensors). Is there a way of using a custom indexer (for example Sensors) that does *not* need to loop through each item in the collection and compare them?
1
893
by: Howard Weiss | last post by:
I would like to create a collection of managed objects - to be exact, instances of a form which I use to display images. This collection would be similar to the controls collection which is part of every Windows form. What is the syntax to create such a collection? Could someone please point me to an example of a Collection of Managed Objects (either strongly typed or not)? Howard Weiss
0
1458
by: Lloyd Dupont | last post by:
I'm trying to create a templated custom control which hold a collection of something else in his property 'Panels' when this property is of type ArrayList it parse ok. however when I try to use a custom typed collection inherited from IList I get an error when parsing: Ligne 4 : <br> Ligne 5 : <galador:SelectPanel runat="server" id="SelectPanel1"> Ligne 6 : <Panels>
1
1407
by: Jeff S | last post by:
I'm storing a list of widgets in a database. The list changes infrequently (twice per week at most), and is relatively short (200 items at most, with very little detail per item). A small subset of all possible widgets will be displayed on a page (using VB.NET/code behind). I plan to populate a custom collection/class with a list of all possible widgets. The class will include a method that returns the required subset. Of course the logic...
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...
1
1061
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...
2
1409
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it seems to work okay on its own, but when I try to bind it to a combobox, the combobox doesn't show anything (and it starts having problems repainting itself). The Datasource appears to contain my custom collection object, but when I ask for its item...
6
2327
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 having to do a httpwebreqeust call.
19
4906
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
0
8427
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
8330
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
8850
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
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2749
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

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.