Combobox in propertygrid?

P

Philip Rieck

You need to implement a type converter for your property.
http://msdn.microsoft.com/library/d...stemcomponentmodeltypeconverterclasstopic.asp


For example, if you have a string property that you want to limit to a few
choices, create a class like this:
public class MyConverter : StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext
context)
{
//true means show a combobox
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext
context)
{
//true will limit to list. false will show the list, but allow free-form
entry
return true;
}

public override
System.ComponentModel.TypeConverter.StandardValuesCollection
GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(
new string[] { "entry1", "entry2", "entry3" });
}

}


Then hook it up to your property like this: (note the [TypeConverter]
attribute)
private string _myProp = "entry1";
[Browsable(true)]
[DefaultValue("entry1")]
[CategoryAttribute("Behavior")]
[TypeConverter(typeof(MyConverter))]
public string MyProp
{
get{ return _myprop;}
set{ _myprop = value;}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top