Is there a way to hide show properties in “CollectionPropertiesEditor’s PropertyGrid” Recently I found out that there is a way to change the PropertyGrid’s Browsable attribute at run time.
I want to know if this can be done to a “CollectionPropertiesEditor’s PropertyGrid”, I have been un-successful at finding relevant results on Google Search. Now I have my hopes on StackOverflow to help me solve this problem.
Problem: I had to add some properties to GridColumn control due to new customer requirements.
[Category("Extra")]
[Browsable(true)]
public int? Position { get; set; }
[Category("Extra")]
[Browsable(true)]
public string storedColumn { get; set; }
What I was hoping to work earlier:
[Category("Extra")]
[Browsable(matchSomeRunTimeCondition)]
public int? Position { get; set; }
[Category("Extra")]
[Browsable(matchSomeRunTimeCondition)]
public string storedColumn { get; set; }
Why it does not work?
Because Browsable Attribute can only accept Constant. And matchSomeRunTimeCondition
is not a constant. A user can change it when-ever he wants while the application is still running.
In code if there is a function that I can use to make these invisible at run-time I will be really greatful if someone can help me write one such function or conditional statement like so:
If (property’s category == “Extra”) {
//Do not show this property in the propertygrid.
//Or in other words, make Browasable Attribute False at run time.
}
At compile time I am setting the Browsable property to true
because it needs to be visible in some conditions. But I need a mechanism to hide this based on user's choice at runtime.
This problem was overcome in the propertygrid by means of setting it while loading the selected control as explained the post: Make all properties with specific Category name invisible in PropertyGrid in c# Winforms at Runtime based on some condition
However in the CollectionPropertiesEditor that I use to hold my grid columns does not have this luxury (at least I could not find out how to do it).
I store all the grid columns of my grid in the form of list of GridColumns as a property.
This is how I am currently storing the GridColumns in the Grid’s properties:
[Browsable(true)]
[Editor(typeof(CollectionPropertiesEditor), typeof(UITypeEditor))]
public List<TGridColumn> Columns { get; set; }
Here I don’t know how to pass my condition to make the aforementioned columns disappear at runtime.