Possible Duplicate:
Conditional 「Browsable」 Attribute如何在propertygrid c#中的屬性中設置BrowseAttribute true或false?
我定義了AppSettings
類,它有幾個屬性。在我的表格中,當我,我想要顯示屬性1和2(1,2顯示,其他屬性隱藏或不顯示),當click Button2
,我想顯示屬性2和3(1是隱藏,2,3是顯示,其他屬性隱藏或不顯示),我該怎麼做?
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; }
}
我想要動態變更BrowseAttribute
爲true或false。我該怎麼做 ?
形式的代碼是:
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;
這種變化有錯誤:
public static bool state = true;
BrowsableAttribute(state)
錯誤:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
對於PropertyGrid中,ID使用的TypeConverter - 平凡然後 –