Dynamically enumerating values for a property in .Net
-
21-08-2019 - |
Question
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.
Solution
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.
OTHER TIPS
This article on CodeProject explains how to write a custom TypeConverter
or UITypeEditor
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow