Solved

Radio Buttons and Enum

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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