Winform User Settings - Allow multiple choice values at Runtime

Posted by Refracted Paladin on Stack Overflow See other posts from Stack Overflow or by Refracted Paladin
Published on 2010-04-01T14:02:47Z Indexed on 2010/04/01 14:13 UTC
Read the original article Hit count: 492

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms