I created a simple User Settings Dialog by binding the Property.Settings
to a PropertyGrid
.
This works like a charm but now I would like to allow only certain choices for some values. I have noticed that some Types will give a dropdown of possible choices. This is what I am shooting for but for, say, Strings.
Example, one of the Settings is UserTheme which is a String. Black, Blue, Silver. The program reads that string from the Settings File and sets the Theme on Startup.
I can type in a correct theme and it works but if I type in Pink it will not as there is not a pink option.
This is my VERY simple UserSettingsForm code.
#region FIELDS
internal Settings userSettings;
#endregion
#region EVENTS
private void frmEditUserControl_Load(object sender, EventArgs e)
{
userSettings = Settings.Default;
this.propertyGrid1.SelectedObject = userSettings;
this.propertyGrid1.PropertySort = PropertySort.Alphabetical;
}
private void btnSave_Click(object sender, EventArgs e)
{
userSettings.Save();
//this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
userSettings.Reload();
this.Close();
}
#endregion
EDIT
Okay, following the advice here I created a library file with my enum
in it. Referenced the dll
in my main app. Now in settings
I see the enum
but the dropdown
only gives the first enum
as an option. Ideas?
namespace psWinForms
{
public enum UserTheme
{
Blue,
Black,
Silver,
Green,
Pink
};
}