locked
Having variable property type inside class RRS feed

  • Question

  • Hello

    I'm having a hard time doing some Modal Type Editor.

    My custom form Type Editor Form contains two property grids. One recieves a class and its properties. The other one is supposed to have the properties of an object created at design-time, according to the properties of this. So, the class is like this:

    public class Item
        {
            private string name = "";
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
    
            private /*TypeGenerated*/ C = new /*TypeGenerated()*/;
            public /*TypeGenerated*/ Col
            {
                get { return C; }
                set { C = value; }
            }
    
            private ObjectType OT = ObjectType.CheckBox;
            public ObjectType ObjectType
            {
                get
                {
                    return OT;
                }
                set
                {
                    OT = value;
                }
            }
        }
    
    public enum ObjectType
        {
            ComboBox = 1,
            CheckBox = 2
        }

    The property ObjectType defines the kind of object that will be generated and then displayed in PropertyGrid2.

    The problem is, how can I save than object then on a property inside Item class? I cant save it as object, because i need it to be persisted in the Designer of a form. I think this is a design flaw, but i dont know any other way to do it. 

    Can somebody help me?


    • Edited by aiui Saturday, March 17, 2012 12:35 PM
    Saturday, March 17, 2012 12:33 PM

Answers

  • Your C property should be a base class or interface of every type it can be. At worst, make it an Object.
    • Proposed as answer by Lie You Thursday, March 22, 2012 3:18 AM
    • Marked as answer by aiui Thursday, March 22, 2012 11:28 AM
    Monday, March 19, 2012 10:13 AM

All replies

  • Hello, aiui.  Welcome to the MSDN C# General Forum.

    Let's make sure that we are on the same page and talking about the same things.  Objects are not "created" at design time.  Objects are not "created" at compile time.  Objects are "created" at run time.  I am uncertain of your meaning of the term " Modal Type Editor ".

    User Interface TypeEditorsOverview - MSDN – Explore Windows ... 

    Walkthrough: Implementing a UI TypeEditor   

    http://msdn.microsoft.com/en-us/library/fd3kt7d5.aspx  how to create type editor for custom type. 

    Hope this helps.

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, March 17, 2012 3:24 PM
  • hello Rodedog2

    thank you for your answer.

    Allow me to try to explain what I'm trying to do.

    I created a UI Type Editor already. I have a modal form that has 2 property grids. That's my Type Editor. Let's say you work with me in a development team. I am creating a user control that you can put in a Form that you're creating. That user control has a property named Filter. When you try to modify that property, my UI Type Editor form is displayed. 

    Now, that form where you can edit the property Filter has one listbox and two property grids.

    The listbox contains items of the class Item, that I displayed in my first post. You can edit those items adding/removing and changing each Item properties, which are displayed in PropertyGrid Nº1. One of those properties is an enum. That enum tells me what kind of object that Item will have associated.

    Now, let's change that enum property to, let's say, ComboBox, I want PropertyGrid Nº 2 to display the properties of a ComboBox. So far so good, i did that already. Now the question is, how can I save the properties of ComboBox? I could do a Property inside Item to host the ComboBox, but the problem is that the enum tells me what type of object should be associated with that particular Item. Should I have one property for each possible value that the enum contains?

    I'm sensing that this is a pretty basic question, but i'm stuck here.

    If you need any more details let me know. Thanks :)

    Saturday, March 17, 2012 4:27 PM
  • Use Cloneing, implement ICloneable to clone object. 

    • Proposed as answer by Lie You Thursday, March 22, 2012 3:18 AM
    Saturday, March 17, 2012 4:40 PM
  • Your C property should be a base class or interface of every type it can be. At worst, make it an Object.
    • Proposed as answer by Lie You Thursday, March 22, 2012 3:18 AM
    • Marked as answer by aiui Thursday, March 22, 2012 11:28 AM
    Monday, March 19, 2012 10:13 AM