Connecting Tech Pros Worldwide Help | Site Map

Combobox in propertygrid?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 15th, 2005, 09:13 PM
Daniel
Guest
 
Posts: n/a
Default Combobox in propertygrid?

How do I use a combobox in a propertygrid without using enum ?
Any suggestions?



  #2  
Old November 15th, 2005, 09:14 PM
Philip Rieck
Guest
 
Posts: n/a
Default Re: Combobox in propertygrid?

You need to implement a type converter for your property.
http://msdn.microsoft.com/library/de...classtopic.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.StandardValues Collection
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;}
}



"Daniel" <bb@aa.com> wrote in message
news:OAqXlK79DHA.4088@tk2msftngp13.phx.gbl...[color=blue]
> How do I use a combobox in a propertygrid without using enum ?
> Any suggestions?
>
>[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.