By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,989 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,989 IT Pros & Developers. It's quick & easy.

Issue with CollectionEditor handling multiple sub-types

P: n/a
Hi all,

I am having an issue with a custom CollectionEditor. My scenario is as
I have a base type TypeA. I also have a TypeACollection. The TypeACollection
has an Editor attribute of TypeACollectionEditor. This collection editor
derives from the framework CollectionEditor, passing TypeACollection in the
constructor to indicate which type it deals with.

I then have TypeB, which derives from TypeA, but adds specific
functionality. I have then created a TypeBCollectionEditor, which handles
editing TypeB instances.
I then have 2 properties on an object, both of TypeACollection, as this can
contain both TypeA and TypeB instances.
Only 1 instance of the collection will ever deal with the 1 type. I.e. no
collection will ever have to contain both TypeA and TypeB objects.
I therefore specify an attribute on the PROPERTY which will contain TypeB
objects that the editor is TypeBCollectionEditor, to override the default
type based value on the TypeACollection of TypeACollectionEditor.

My TypeBCollectionEditor derives from TypeACollectionEditor, and I was
planning on simply overriding a couple of methods such as CreateNewItemTypes
and CreateInstance to return TypeB specific details.
This all looked fine - when I clicked "Add" the correct type was being
created based on which property I was editing. However, when I close the
collection editor form and the component I am editing, and then re-open the
component in VStudio, and then edit the collection which should contain
TypeB objects, the form is created, with the previously configured info, but
the items are created as TypeA objects, NOT TypeB. The only method that
seems to be called before the form loads and displays is GetItems, but by
then the TypeA objects have already been created and cannot be cast to
TypeB, as TypeB is more specific.

Has anyone got any ideas what I am doing wrong, or exactly which methods I
need to override? All CollectionEditor methods I override are called too
late, and the CollectionEditor form has already displayed with incorrect
types. I think it is something to do with the CollectionEditor looking at
the indexer of the collection and picking that type?

Thanks heaps,

Feb 2 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.