CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    112

    Typeconverters for Abstract Classes

    I have a Property Grid which I am trying to use to display a complex object.

    The object in question contains a collection of objects that all derive from the same abstract class. I want to be able to use the property grid to add new items to that collection.

    I have used a type converter to allow that object to appear as expandable so that I can access it's properties (including the collection). When I attempt to add new items to the collection I receive errors because the class it is trying to create is the abstract base class rather than the child classes.

    How can I make it so that when you attempt to add a new item to that collection, it will ask you what type of object to create (instead of defaulting to the abstract base class).

    To give you a better understanding, my structure is something like this:

    public class class1
    {
    private class2[] collection;

    public class2[] Collection
    {
    get{ return collection; }
    set{ collection = value; }
    }
    }

    // When adding to the collection, it attempts to create an instance of this
    // class which fails. It needs to have a way to determine whether to create
    // an instance of class3 or class4 instead.
    [TypeConverter(typeof(Class2TypeConverter))]
    public abstract class2
    {

    }

    public class3 : class2
    {
    }

    public class4 : class2
    {
    }

  2. #2
    Join Date
    Nov 2002
    Location
    Baby Land
    Posts
    646

    Re: Typeconverters for Abstract Classes

    This is not exactly what you needed but perhaps it would give some pointers:
    http://www.urbanpotato.net/Default.aspx/document/2001

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured