Is it possible to attach a List of strings to a String property so that the user can select one of the strings from the Properties window? Should I implement ICollection or something of that sort?
for example, I have a user control that contains textbox which allows users to filter rows in a DataGridView. I want to provide some filter strings for them to be able to select from the GUI builder instead of having to do it programatically.
alexD
2009-09-26 00:59:00
You can Use dropdownList control and insert your string filter in the html side, As if you want to use the enums, there might be possibility that your one option of string may contain 2 words means it contain space.
Asim Sajjad
2009-09-26 01:42:49
+3
A:
If you are trying to restrict a property to one of a few specific options, you should use an Enum instead of a String for the property.
If you want to provide defaults, but let them type any string in and ignore the defaults, then you can use StringConverter. For details, read Getting the Most Out of the .NET Property Grid control. It covers this exact scenario.
Reed Copsey
2009-09-26 00:53:20
I checked that link out but it appears that it tells you how to do it for a PropertyGrid object - I can't get this to work in my design-time Properties window. Everything I've found seems to be for a PropertyGrid control - is there any way to do this at design time?
alexD
2009-09-28 17:38:33
That's the same thing. The design time properties windows IS a PropertyGrid control - if you do what it's describing, it will display that way at design time.
Reed Copsey
2009-09-28 17:40:37
Thank you this worked...I accidentally had the wrong type in my Attribute (had StringConverter but my class name was ColumnStringConverter, so it wasn't working).
alexD
2009-09-28 22:45:41
+3
A:
No. You should create an enum
type with your string choices, and make the property of that type. Example:
public enum Choices
{
NiceChoice,
PoorChoice
}
public class Chooser
{
public Choices Choice { get; set; }
}
Tomas Lycken
2009-09-26 00:54:07
I can't use an enum because the list is dynamically generated. Basically when the user sets the datasource for a DataGridView, the property is going to read the column names and populate the list with those names. The user will then be able to select which column they want to filter.
alexD
2009-09-28 17:39:34