I am working on a custom component, and now I need to add a public property that is visible in properties windows
of VS.
This property must be a list of values where the user can choose from. Like a combobox.
I googled around a lot and found this question on SO and tried it, but it seems a lot of work so I wanted a more elegant way. Also, with this code I have no notification when a user chooses an item from the list.
So I found that the proper way of showing a list a user can choose from (on a custom component's properties in the property window of VS) is like the code below
public enum BUTTONSTYLE { Style_Solid, Style_GradientA, Style_GradientB, Style_Image, Style_Liquid };
BUTTONSTYLE _buttonStyle;
[DefaultValue(BUTTONSTYLE.Style_Solid)]
[Category("Appearance")]
[Browsable(true)]
[Description("Sets style of the button")]
public BUTTONSTYLE newbuttonstyle
{
get
{
return _buttonStyle;
}
set
{
_buttonStyle = value;
}
}
While this works very well, my problem is that this needs a enum that is defined and cannot change. In my case the values in BUTTONSTYLE
can change. But it's not possible to change the items in an enum. Allthough this answer says it can be done, I tried it and it did not work.
So I am thinking that probably I am doing this a complete wrong way.
How can I add such kind of property to my custom control the proper way ?
For clarity, the property is not a combobox, but should let the user pick a value like if it was a combobox
EDIT
for clarity I will try to explain in other words what my problem is.
I need a property that will present a list to the user, so he can pick an item from this list.
What I found so far is that I should use an enum for this, that will show up in the propertie window as a list (see also the image) where the user can pick from.
But, this is not usefull for me because when I use an enum than the items in the list are defined at designtime and cannot change.
In my case, the items that are presented to the user could change, based on the values of other properties.
So I cannot use an enum after all, so what is the proper way to do this ?
I hope my problem is a bit more clear now