Kawa
Kawa

Reputation: 1488

Dynamically enumerating values for a property in .Net

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.

Upvotes: 1

Views: 211

Answers (2)

Tim Robinson
Tim Robinson

Reputation: 54734

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.

Upvotes: 2

Daniel Brückner
Daniel Brückner

Reputation: 59645

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

Upvotes: 1

Related Questions