Create new class which inherit StringCoverter, and 3 methods:
internal class List2PropertyConverter : StringConverter
{
public override bool
GetStandardValuesSupported(
ITypeDescriptorContext context)
{
//True - means show a Combobox
//and False for show a Modal
return true;
}
public override bool
GetStandardValuesExclusive(
ITypeDescriptorContext context)
{
//False - a option to edit values
//and True - set values to state readonly
return true;
}
public override StandardValuesCollection
GetStandardValues(
ITypeDescriptorContext context)
{
return new StandardValuesCollection(
new string[] {"test1", "test2", "..."});
}
}
Add variable and encapsulate it:
private string testValue;
[Browsable(true)]
[Category("Category name")]
[TypeConverter(typeof(List2PropertyConverter))]
public string TestValues
{
get { return testValue; }
set { testValue = value; }
}
PropertyGrid has 4 attributes for a manage properties:
[Browsable(bool)] - Visible/Hide property
[ReadOnly(bool)] - Editing (true/false)
[Category(string)] - Group of properties
[Description(string)] - Description of the property
Regards,
6 comments:
Thanks! It was surprisingly hard to find a simple solution to this out there.
This sample is great and really hard to find. Thanks
Very helpful, Thank you.
Is there any chance someone could describe how to select/highlight an item from the ComboBox?
Many thanks 8~)
super helpful. Simple & useful. Thanks!
if I want to load at run time the list in the combobox's items, how can I do?
Just as effective as needed!! Amazingly simple ... I just wonder how dou you get to this? I thinked it always has to through a UITypeEditor
Post a Comment