How to create virtual properties with AdvPropertyGrid for WinForms
Categories: DotNetBar for Windows Forms, How To
DotNetBar for Windows Forms Advanced PropertyGrid control provides complete support for ICustomTypeDescriptor interface that you can use to provide completely virtual properties that are shown and edited in property grid.
This involves implementing ICustomTypeDescriptor interface on your object and the at least providing list of custom properties returned from GetProperties(Attribute[] attributes) method that you implement as part of ICustomTypeDescriptor interface.
Download C# project that shows how to do this.
Download VB project that shows how to do this.
Related posts:
The C# example didn’t quite go into detail on how to customize the various attributes, such as category, description, etc. You can accomplish this by changing some of the details of the ‘private PropertyDescriptor[] GetCustomProperties()’ routine:
_Properties = new PropertyDescriptor[14];
_Properties[0] = new MyCustomProperty(“Exit Message”, new Attribute[2] { new DescriptionAttribute(“The message to show once you leave chat”),new CategoryAttribute(“Chat Settings”) } , typeof(string));
The above, for example, would allow you to set a description, and category for your desired custom property. You can include any useable Attribute that it supports, just make sure you have the proper number of ‘Attribute[X]‘ include in there. if you only need 1, good habit is to still include ‘Attribute[1]‘, but you can also just do ‘new[]‘, as it is in the example C# file.