Solved

Radio Buttons and Enum

Posted on 2010-09-02
3
590 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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