471,573 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

Issue with CollectionEditor handling multiple sub-types

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
0 1041

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
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

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.