views:

26

answers:

0

I'm still learning the ropes when it comes to implementing custom editors for complex properties at design time.

As a simple starting point, I'm trying to enable design-time editing of a property of type ICollection<string>.

What I've done so far is:

  • Wrote a StringsEditor class, which derives from UITypeEditor and displays a drop-down into which the developer can input a bunch of strings on separate lines, which are subsequently added to a collection. This works fine.
  • Wrote a StringsConverter class, which derives from TypeConverter and converts between objects of type string and ICollection<string> (well, any type T that implements ICollection<string>) so that when the developer closes the drop-down displayed by the StringsEditor, the text that appears in the box is a comma-delimited list of the strings entered. Reopening the drop-down displays the strings again, one per line.

The result of my work so far is that everything appears to work great during design time. The user can modify the property, adding and removing strings to his/her heart's content and the text displayed in the property grid matches what's in the collection.

What I haven't been able to figure out yet--and this doesn't surprise me-- is how to actually save this collection beyond design time, so that the values entered... you know, stay there. My understanding is that currently, the property is being edited at design time (by me), but since none of the changes I'm applying have any effect on the generated InitializeComponent method of the control, there's no effect on the class I'm designing (only the instance presently displayed by my IDE).

But obviously, it is possible to get your values into that InitializeComponent call. In fact, I just happened by accident to discover that this magically "just works" for properties of type DirectoryInfo with an appropriate UITypeEditor (I made another editor called DirectoryEditor that just displays a FolderBrowserDialog and provides a DirectoryInfo object for whatever path is selected, and this surprisingly did end up updating the class's InitializeComponent method). So I know it can be done. I'm just looking for someone to point me in the right direction.