Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I have problem with my two groups of radiobuttons(first group have 4 radiobuttons, second have 2 radiobuttons). I would like not to label any of the radiobuttons to pop up a messagebox. For example firstgroupname(level) when not marked message box show "You must marked what level do you want". I´m coding WPF Application. For clarification:
if the user does not mark in one group and in the other yes a message pops up, when the user marks in one group and in another no the other message pops up,
if he does not mark the connection of the two previous messages even in one of them. It would certainly be possible to list all the possibilities, but there would be a lot of it, so I ask about the possibilities of the group

What I have tried:

For example:
C#
if (plus.IsChecked.HasValue == true && plus.IsChecked.Value == true && low.IsChecked.HasValue == true && low.IsChecked.Value == true)

this is how I get it when it is chosen from both groups
C#
else if (level.IsChecked.HasValue == false && level.IsChecked.Value == false && difficul.IsChecked.HasValue == true && difficul.IsChecked.Value == true)
           {
               MessageBox.Show("You must marked what level do you want!");

           }

like this
Is it possible?

Thank you for any advice!!!
Posted
Updated 28-Aug-21 1:23am
v3
Comments
Maciej Los 23-Apr-21 7:39am    
Sorry, but your question is unclear...
dejf111 23-Apr-21 8:15am    
sorry i don't know how to explain
dejf111 23-Apr-21 8:23am    
maybe now is better
Maciej Los 23-Apr-21 8:42am    
Nope...
dejf111 23-Apr-21 8:46am    
never mind I'll make it more complicated

1 solution

Instead of doing that, use WPF data binding. That way, there is no need for endless and complicated "if/then/else" statements.

0) Create an int property that indicates a radio groups current selection. Set it to 0 as a default (indicating no selection).

1) Handle all of the radio group buttons' click event handlers in one method that sets the int property's value based on which radio button was clicked

2) When it's time to make a decision based on radio button selection, simply write a switch statement that evaluates the int property.

It ain't hard.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900