469,269 Members | 1,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,269 developers. It's quick & easy.

Issue with CollectionEditor handling multiple sub-types

Hi all,

I am having an issue with a custom CollectionEditor. My scenario is as
follows:
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,

Bardo.
Feb 2 '07 #1
0 992

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by m. pollack | last post: by
reply views Thread by m. pollack | last post: by
reply views Thread by m. pollack | last post: by
reply views Thread by Chris McKenzie | last post: by
reply views Thread by juststarter | last post: by
reply views Thread by --== Alain ==-- | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.