Solved

Radio Buttons and Enum

Posted on 2010-09-02
3
588 Views
Last Modified: 2013-12-17
Experts,

How do I bind Radio Buttons to Enums?

ARadBut and BRadBut are two radio buttons. When I click on ARadBut I want the AVal of 2 and when I set AVal to 2 I wand the ARadBut turned on. Am I on the right track?

public enum ABEnum { None = 0, AEnum = 2, BEnum = 4 };

        public ABEnum AVal
        {
            get
            {
                if (ARadBut.Checked)
                {
                    return ABEnum.AEnum;
                }
                else
                {
                    return ABEnum.None;
                }
            }
            set
            {
                ARadBut.Checked =  //What goes in here?
            }
        }

        public ABEnum BVal
        {
            get
            {
                if (BRadBut.Checked)
                {
                    return ABEnum.BEnum;
                }
                else
                {
                    return ABEnum.None;
                }
            }
            set
            {
                BRadBut.Checked = //What goes in here?
            }
        }
0
Comment
Question by:San24
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
richard_hughes earned 500 total points
ID: 33587878
Hello San24

Try the code below:

Thank you very much,

Richard Hughes
public enum ABEnum { None = 0, AEnum = 2, BEnum = 4 };

        public ABEnum AVal
        {
            get
            {
                if (ARadBut.Checked)
                {
                    return ABEnum.AEnum;
                }
                else
                {
                    return ABEnum.None;
                }
            }
            set
            {
                ARadBut.Checked = value == ABEnum.AEnum;
            }
        }

        public ABEnum BVal
        {
            get
            {
                if (BRadBut.Checked)
                {
                    return ABEnum.BEnum;
                }
                else
                {
                    return ABEnum.None;
                }
            }
            set
            {
                BRadBut.Checked = value == ABEnum.BEnum;
            }
        }

Open in new window

0
 

Author Comment

by:San24
ID: 33588130
Excellente! Thanks Richard!

I combined the AVal and BVal to a RadVal. It works. Have a look at it and let me know what you think and I can assign you the points and close this thread.

       public enum ABEnum { None = 0, AEnum = 2, BEnum = 4 };

        public ABEnum RadVal
        {
            get
            {
                if (ARadBut.Checked)
                {
                    return ABEnum.AEnum;
                }
                else if (BRadBut.Checked)
                {
                    return ABEnum.BEnum;
                }
                else
                {
                    return ABEnum.None;
                }
            }
            set
            {
                ARadBut.Checked = value == ABEnum.AEnum;
                BRadBut.Checked = value == ABEnum.BEnum;
            }
        }
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 33588149
That looks fine. I wasn't sure if you originally wanted to combine them, so I didn't do that.

Good job!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now