3
我有來自Internet源的此代碼,我認爲此代碼可能適用於將屬性從文本框更改爲PropertyGrid中的組合框,但運行此屬性後,它仍然是文本框。有誰能幫助解決這個問題嗎?將屬性更改爲屬性網格中的組合框
public class Testing
{
private String _formatString;
[Category("Display")]
[DisplayName("Format String")]
[Description("Format string governing display of data values.")]
[DefaultValue("")]
[TypeConverter(typeof(FormatStringConverter))]
public String FormatString { get; set; }
public class FormatStringConverter : StringConverter
{
List<String> list = new List<String>();
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } // true means show combobox
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } // true list to list, false will show the list, but allow free=form.
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
list.Add("Curren");
list.Add("Currency");
list.Add("Scientific Notation");
list.Add("General Number");
list.Add("Number");
list.Add("Percent");
list.Add("Time");
list.Add("Date");
return new StandardValuesCollection(list);
}
}
}