Results 1 to 2 of 2

Thread: custom class in PropertyGrid not changing to ReadOnly

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    custom class in PropertyGrid not changing to ReadOnly

    I have a custom class, "classMain", and inside that class is a property of type "classChild" (another custom class). I already had it set up where the classChild is expandable (by creating my own typeconverter) when used with PropertyGrid. Now, I'm trying to set the ReadOnlyAttribute of the classChild to TRUE at the start by doing this:
    Code:
    public class classChild
    {
       int number;
       public int Number
       {
          get{return number;}
          set{number = value;}
       }
    }
    public class classMain
    {
       classChild child = new classChild();
    
      [ReadOnlyAttribute(true)]
       public classChild Child
       {
          get{return child;}
          set{child = value;}
       }
    }

    When I set the PropertyGrid.SelectedObject to an instance of classMain, the property Child is not being displayed as ReadOnly. I am, however, able to make the property of classChild, Number, to become ReadOnly when I add the ReadOnlyAttribute this way:
    Code:
    TypeDescriptor.AddAttributes(pgInitializeInput.SelectedObject, new Attribute[] { new ReadOnlyAttribute(true) }); //the SelectedObject is referencing an instance of classMain
    or by putting the ReadOnlyAttribute in here instead:
    Code:
    [ReadOnlyAttribute(true)]
    public class classChild
    {
       int number;
       public int Number
       {
          get{return number;}
          set{number = value;}
       }
    }
    I'm guessing I have to something similar that allowed me to make my custom class expandable in the propertygrid, but I don't know where to start. Any ideas?

  2. #2

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