?
Solved

Radio Buttons and Enum

Posted on 2010-09-02
3
Medium Priority
?
596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
richard_hughes earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

771 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