Results 1 to 8 of 8

Thread: Property problems... (Resolved)

  1. #1

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Property problems... (Resolved)

    Hi there.

    Straight to the point :
    I have created a MustInherit base class that users can inherit from.

    In my control I have a property using my baseclass.
    In code, it's no problem to set a derived class to the property, but how to do it in the propertygrid?

    My property is just greyed out, as if it were readonly.

    I mean, if I make a property as Control, the propertgrid automatically let's me select between the controls on the form.
    That is basically the functionality I'm looking for.


    Here's what I been thinking about doing :

    1. Make a custom UITypeEditor.
    2. Enum all the derived classes in the project and showing them in a combobox.
    3. Then instantiate a new class based on the selection.

    So my problems are :
    1. How to enumerate derived classes? (I obviously can't know beforehand how many the user creates)
    2. How to instantiate a new object, when I only got the type?

    3. Does anyone have a better idea on how to do this?


    I don't know if this makes any sense at all, but I hope some can help me with this
    Last edited by pax; Apr 26th, 2004 at 04:38 AM.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  2. #2

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Bump... Anyone???
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Ok, I just figured out how to create a new instance of an object, when I only got the type, using System.Activator.CreateInstance() method.

    Now, all I have to do is enum all classes that inherits my base class.

    Does anyone know how to enum that?
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, I image if its in the same assembly, you could use reflection to do that.. but man what a hassle, just do it the MS way, the user has to type its name in passed through a string... lol.. (i'm thinking of their CssClass property, but maybe thats a bad example, since style classes aren't compiled classes, so that makes sense to use a string).

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Maybe use can use the Parent or container property to find all other instances of your type on the containing control... using getType

  6. #6

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Originally posted by nemaroller
    Maybe use can use the Parent or container property to find all other instances of your type on the containing control... using getType
    Well, I kinda like your idea, but wouldn't that require the class to be instantiated?

    What I need to know, is what types of classes exists in the current project. This means that I have to enumerate the classes from my own DLL, but I also have to enumerate any class that the user made himself, and check if it's derived from my base class.

    So in short, I have to enumrate available classes that haven't been instantiated yet.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  7. #7

    Thread Starter
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi Nemaroller.

    You were right about reflection.
    I can use The AppDomain to get all assemblies in the project.
    Then I loop through them all, getting all types in each assembly.
    Then I loop through each type checking the IsSubClassOf to see if the type is derived from my baseclass.

    And it even works in designtime as well.

    So, thanks for your input, it really got me thinking in the right direction.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    No problem. Pure luck on my part, that one.

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