Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Component Services / February 2004

Tip: Looking for answers? Try searching our database.

Combobox in propertygrid?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel - 20 Feb 2004 13:08 GMT
How do I use a combobox in a propertygrid without using enum ?
Any suggestions?
Philip Rieck - 20 Feb 2004 15:58 GMT
You need to implement a type converter for your property.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemcomponentmodeltypeconverterclasstopic.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;}
 }

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.