views:

127

answers:

2

You know how a TreeView control's ImageList property lists all ImageLists on a form? I need something similar, but with a list of strings. It's like an enumeration, but defined at runtime, with the object that exposes the property in a PropertyGrid.

So, with a list of strings like { "foo", "bar", "grill" } the property should list those but if that list of strings is changed (say, add a "bbq" item), the property should enum { "foo", "bar", "grill", "bbq" } instead.

+1  A: 

This article on CodeProject explains how to write a custom TypeConverter or UITypeEditor.

Daniel Brückner
A type editor is overkill. Just using a TypeConverter is much easier.
Jeff Yates
You can achieve a lot with UITypeEditor, but IME it's overkill for just a list of strings (for instance, you have to create a list control to hold the items). TypeConverter is pretty much automatic.
Tim Robinson
TypeConverters for combo boxes are covered in the article, too.
Daniel Brückner
+2  A: 

If it's just a list of strings you need, take a look at writing your own TypeConverter. You'll need to override the GetStandardValues method.

Tim Robinson