Possible Duplicate:
Conditional “Browsable” Attribute
I define AppSettings
class that have a few properties. In my form, When I click Button1
, I want show property 1 and 2(1,2 is show, Other properties are hide or not displayed), When click Button2
, I want show property 2 and 3(1 is hide, 2,3 are show, Other properties are hide or not displayed), How can I do it ?
public class AppSettings
{
[BrowsableAttribute(true), CategoryAttribute("Document Settings"), DefaultValueAttribute(true)]
public bool SaveOnClose{ get; set; }
[BrowsableAttribute(true), CategoryAttribute("Global Settings"), ReadOnlyAttribute(true), DefaultValueAttribute("Welcome to AppDev!")]
public string GreetingText { get; set; }
[BrowsableAttribute(true), DescriptionAttribute("The rate in milliseconds that the text will repeat."), CategoryAttribute("Global Settings"), DefaultValueAttribute(10)]
public int MaxRepeatRate { get; set; }
[BrowsableAttribute(true), CategoryAttribute("Global Settings"), DefaultValueAttribute(4)]
public int ItemsInMRUList { get; set; }
[BrowsableAttribute(true), DefaultValueAttribute(false)]
public bool SettingsChanged { get; set; }
[BrowsableAttribute(true), CategoryAttribute("Version"), DefaultValueAttribute("1.0"), ReadOnlyAttribute(true)]
public string AppVersion { get; set; }
}
I want change dynamically BrowseAttribute
to true or false. How can I do it ?
Form code is :
AppSettings AppSet = new AppSettings();
AppSet.AppVersion = "2.3";
AppSet.SaveOnClose = true;
AppSet.GreetingText = "Welcome to Dar!";
AppSet.ItemsInMRUList = 4;
AppSet.MaxRepeatRate = 10;
AppSet.SettingsChanged = false;
...
propertyGrid1.SelectedObject = AppSet;
this change has error:
public static bool state = true;
BrowsableAttribute(state)
error:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type