- This topic has 0 replies, 1 voice, and was last updated 8 years, 1 month ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Tagged: Dynamic PropertyGrid
In my current C# project I have to hide and show properties in Propertygrid according to the value selection user makes for another property in property grid.I am facing issues in adding this dynamic behavior using the PropertyGrid control.Is it possible to dynamically set Visible property for a property Item in propertygrid in C#.NET winforms project.
Answer is yes, We can set the browsable attribute of a property to true or false dynamically to make it visible or invisible. Once sample code snippet is below,
public void ModifyBrowsableAttribute(string attribute, object value)
{
var descriptorProp = TypeDescriptor.GetProperties(GetType())[attribute];
var theAttribute = (BrowsableAttribute)descriptorProp.Attributes[typeof(BrowsableAttribute)];
var isBrowsable = theAttribute.GetType().GetField(“browsable”, BindingFlags.NonPublic | BindingFlags.Instance);
isBrowsable.SetValue(theAttribute, value);
}
© Copywright 2017 Dotnetstuffs All Rights Reserved