• Status: Solved
• Priority: Medium
• Security: Public
• Views: 603

# Radio Buttons and Enum

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
{
{
return ABEnum.AEnum;
}
else
{
return ABEnum.None;
}
}
set
{
ARadBut.Checked =  //What goes in here?
}
}

public ABEnum BVal
{
get
{
{
return ABEnum.BEnum;
}
else
{
return ABEnum.None;
}
}
set
{
BRadBut.Checked = //What goes in here?
}
}
0
San24
• 2
1 Solution

Commented:
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
{
{
return ABEnum.AEnum;
}
else
{
return ABEnum.None;
}
}
set
{
ARadBut.Checked = value == ABEnum.AEnum;
}
}

public ABEnum BVal
{
get
{
{
return ABEnum.BEnum;
}
else
{
return ABEnum.None;
}
}
set
{
BRadBut.Checked = value == ABEnum.BEnum;
}
}
``````
0

Author Commented:
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 };

{
get
{
{
return ABEnum.AEnum;
}
{
return ABEnum.BEnum;
}
else
{
return ABEnum.None;
}
}
set
{
ARadBut.Checked = value == ABEnum.AEnum;
BRadBut.Checked = value == ABEnum.BEnum;
}
}
0

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

Good job!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

• 2
Tackle projects and never again get stuck behind a technical roadblock.