views:

82

answers:

0

Possible Duplicate:
Return Enum From Function C#

This was originally posted here link but I could not get a suitable reply in the comments field (not enought characters) and could not find another way other than to start again here :(

Firstly thanks to all who replied.

In an attempt to simplify this question, it appears I have used the wrong analogy of upper/lower case and some of you have got the wrong idea - clearly not your fault :)

This is the code I have so far and allows you to choose between ChoiceOne and ChoiceTwo

    public partial class CustomControl1 : Control
    {
    public enum ChoiceOne
    {
        SubChoiceA,
        SubChoiceB,
    }
    public enum ChoiceTwo
    {
        SubChoiceC,
        SubChoiceD,
    }
    public enum Choice
    {
        ChoiceOne,
        ChoiceTwo,
    }

    private Type _subChoice;
    private Choice _choice;

    public Type SetSubChoice
    {
        get
        {
            if (_choice.Equals(Choice.ChoiceOne))
            {
                return typeof(ChoiceOne); 
            }
            else
            {
                return typeof(ChoiceTwo);
            }
        }
        set
        {
            _subChoice = value; 
        }
    }

    public Choice SetChoice
    {
        get
        {
            return _choice;
        }
        set
        {
            _choice = value;
        }
    }      
    }

What happsens in VisualStudio is that property grid allows you to set the SetChoice property between ChoiceOne and ChoiceTwo which is correct.

The problem is that the SetSubChoice property is greyed out but it does set to either 'WindowsFormsApplication4.CustomControl1+ChoiceOne' or 'WindowsFormsApplication4.CustomControl1+ChoiceTwo' dependent upon what SetChoice is set to. What I want is to be able to use SetSubChoice to pick SubChoiceA or SubChoiceB or SubChoiceC or SubChoiceD depending on what SetChoice is set to.

So for example, if SetChoice is set to ChoiceOne then SetSubChoice will allow me to choose between ChoiceA or ChoiceB. Likewise if SetChoice is set to ChoiceTwo then SetSubChoice will allow me to choose between ChoiceC or ChoiceD.

Hopefully this has clarified things a little more?

We are almost there now :) keep the ideas coming.

Thanks