M
mkruluts
Guest
I have a tabbed application, and within each tab consists a PropertyGrid control. The PropertyGrid's selected object is a single class that accounts for all possible properties. The catch is, depending on the type of product assigned to the tab, some properties are not browsable at all. The class defaults each of these variable property's Browsable attribute to false, and the code enables the appropriate property at run-time.
Believe it or not, this works perfectly for the first tab to be opened in the application, regardless of the type of product assigned to the tab. The problem is, setting the Browsable attribute with more than one tab opened, affects all opened tabs.
Is there any way to do this on just the single instance of the class and not all instances of the class? If it cannot be done at the class level, is there any way to extend the PropertyGrid control to hide properties programmatically regardless of the attribute from the class?
Below is the logic I am working with to set the attribute at run-time. Please let me know if you guys have any ideas.
private void SetPropertyBrowsable(string PropertyName, bool Browsable)
{
try
{
PropertyDescriptor _PropertyDescriptor = TypeDescriptor.GetProperties(this.GetType())[PropertyName];
if (_PropertyDescriptor != null)
{
BrowsableAttribute _BrowsableAttribute = (BrowsableAttribute)_PropertyDescriptor.Attributes[typeof(BrowsableAttribute)];
FieldInfo _IsBrowsable = _BrowsableAttribute.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance);
_IsBrowsable.SetValue(_BrowsableAttribute, Browsable);
}
}
catch (Exception) { /* DO NOTHING */ }
}
Continue reading...
Believe it or not, this works perfectly for the first tab to be opened in the application, regardless of the type of product assigned to the tab. The problem is, setting the Browsable attribute with more than one tab opened, affects all opened tabs.
Is there any way to do this on just the single instance of the class and not all instances of the class? If it cannot be done at the class level, is there any way to extend the PropertyGrid control to hide properties programmatically regardless of the attribute from the class?
Below is the logic I am working with to set the attribute at run-time. Please let me know if you guys have any ideas.
private void SetPropertyBrowsable(string PropertyName, bool Browsable)
{
try
{
PropertyDescriptor _PropertyDescriptor = TypeDescriptor.GetProperties(this.GetType())[PropertyName];
if (_PropertyDescriptor != null)
{
BrowsableAttribute _BrowsableAttribute = (BrowsableAttribute)_PropertyDescriptor.Attributes[typeof(BrowsableAttribute)];
FieldInfo _IsBrowsable = _BrowsableAttribute.GetType().GetField("browsable", BindingFlags.NonPublic | BindingFlags.Instance);
_IsBrowsable.SetValue(_BrowsableAttribute, Browsable);
}
}
catch (Exception) { /* DO NOTHING */ }
}
Continue reading...