How do I add a group in property grid without using category?
i need to group the properties in property gr开发者_JS百科id with out using category
Decorate the property with the CategoryAttribute
, and specify the name of the category in which you want the property to appear. If that category does not already exist, a new one will be created automatically.
For example, if you have a property UserName
that you want to appear under the custom category "Users" in the Properties Window, you would write the following code in your custom control:
[Category("Users")]
public string UserName
{
get { return _userName }
set { _userName = value }
}
If you want your property to appear in an existing category (one of those that already appears in the Properties Window), you should specify that category's name instead. For example, if I wanted the UserName
property to appear in the "Data" category, I would simply change the above code to:
[Category("Data")]
public string UserName
{
get { return _userName }
set { _userName = value }
}
"sorry friend just now saw your reply, i need to create sub groups within the group like Font group present in the property grid, within that group the properties like Name,Size, unit will be present"
What you seem to be describing in your comment are sub-properties. For simple types like float if you expose them as a property the PropertyGrid already knows how to display them and edit them. User defined classes have a default implementation that allows no editing and displays the class name. If you want to display properties inside your class, you need to add this above your class definition:
[TypeConverter(typeof(ExpandableObjectConverter))]
That tells the property grid to allow your property to be expanded to see the properties inside it.
Lots more information on the PropertyGrid can be found here: Getting the Most Out of the .NET Framework PropertyGrid Control
精彩评论