Solved

Radio Buttons and Enum

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

17 Experts available now in Live!

Get 1:1 Help Now