0

Let's say we have a couple of RadioButton objects (all: not selected) and we select one of them.

So what I want to know is; how to determine whether we had a RadioButton selected or not. How can I acheive this in c#?

Draken
  • 3,134
  • 13
  • 34
  • 54
Michael1248
  • 150
  • 1
  • 12

1 Answers1

1

See if any radio button is checked as follows;

var checkedButton = container.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);

If checkedButton remains null then that means you have never selected any of these radio buttons.

In wpf, try following;

 var checkedButton = container.Children.OfType<RadioButton>().FirstOrDefault(r => (bool)r.IsChecked);

Refer this for more description.

Community
  • 1
  • 1
Kamalesh Wankhede
  • 1,475
  • 16
  • 37
  • that is fine if I would call it outside of the CheckedEvent. Calling it inside the CheckedEvent throws still [wrong] result (true result, but not the intended). – Michael1248 Oct 07 '16 at 06:52
  • Well, you could call it on Page shown event and store its result in some field. Then you could access that field in your CheckedEvent. – Kamalesh Wankhede Oct 07 '16 at 08:36
  • at the moment I store the value in the Parents TagProperty, but to store it in a field would also be a solution. – Michael1248 Oct 07 '16 at 11:20