Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Property Grid - displaying nested properties
 

Property Grid - displaying nested properties

Hi !
 Consider the following class definitions:

Class Student
{
   //members
   public int m_Age;
   public string m_Name;

   //Properties
   public string Name{ get{return m_Name;}}
   public string Age{ get{return m_Age;}}
}


Class School
{
   Student s1;
   string m_SchoolName;
   
   School() 
   {
       s1.m_Age = 14;
       s1.m_Name = "Joe";
   }

   //Properties
   pubic string SchoolName{get{return m_SchoolName;}}
   public Student1{get{return s1;}}
}


Now, I create an object of class School say objSchool. Then I can display the properties of this object in the property grid. 

BUT...while displaying the property Student1, the properties of object s1 are not displayed :-(    What I want is a [+] sign to be displayed...and when expanded, it should reveal the properties of s1!  For eg. in while displaying the properties for a Form, we see a [+] sign next to Size...and on clicking it, the proerties of Size object namely width/height are shown !!
MigrationUser 1  Tuesday, July 22, 2003 10:47 AM
Hello, the best way to solve this problem would be to write your own TypeConverter for your 'Student' class.  Once this is done, add the attribute '[TypeConverterAttribute(typeof(StudentTypeConverter))]' above your 'Student' class and you should be able to expand the type in the PropertyGrid.  You also may be able to solve this problem by simply using the pre-defined TypeConverter 'ExpandableObjectConverter' instead of deriving your own type.

Hope that helps,
-Fred

MigrationUser 1  Tuesday, July 22, 2003 5:07 PM
of course, if the an object subclasses from System.ComponentModel.Component it will automatically expand.  I believe that is because of the ComponentConverter, I haven't dug that deeply into it.  I'm not suggesting that Student be a component, but this is why most controls don't (such as user controls) don't exhibit this problem.

- Dennis
MigrationUser 1  Tuesday, July 29, 2003 10:24 PM

You can use google to search for other answers

Custom Search

More Threads

• Property with System.Flags attribute display problem
• How to do this...in vs 2005??
• I Need Help With An Error Message My Control Generates!
• Support Multi Languages
• Custum Button applying 3DBorderStyle (help please)
• How can I implement the property DataBindings in a Smart Tag of a control
• Ambiguous match found
• Displaying list of typed datasets
• How to Avoid the Scroll Bar Flickering in Panels
• Disappearing Tab Controls