changing the property of class file at run time
how to change the property name of class file at run time which is being used as property in propertygrid
ex)
public class propertygrid_sample
{
string m_DisplayString;
public string Text
{
get { return m_DisplayString; }
set { m_DisplayString = value; }
}
//some code to change the name
}
When propertygrid.selectedobject == propertygrid_sample
class object, then name Text
will get displayed as property in property grid after compilation. I need TextAli开发者_如何学Cgn
to be displayed when accessing the property Text
. By making [DisplayName("TextAlign")] i able to get solution but i am expecting some code to make the change at run time
It sounds like you're looking for something like this:
http://www.codeproject.com/KB/grid/PropertyGridDynamicProp.aspx
Use the display name attribute
[DisplayName("Other Name")]
public string Text { ... }
You need custom TypeDescriptor attached to your class via attribute TypeDescriptionProviderAttribute.
In your custom TypeDescriptor class you need override method GetProperties() and return edited instances of PropertyDescriptor class.
All of *Descriptor classes are meta-data classes supposed to propagating the types/members with changes - such as renaming the type/member.
Some samples with *Descriptor classes:
- Understanding the TypeDescriptor: A Metadata Engine for Designtime Code
- Dynamic Properties in the PropertyGrid
精彩评论