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?
Re: custom class in PropertyGrid not changing to ReadOnly
Just make the property itself readonly:
Code:
public classChild Child
{
get{return child;}
}