Force user to select the Radio Button inside the GroupBox

1

How do I force user to select a Radio Button within the GroupBox.

Image example below

    
asked by anonymous 05.10.2017 / 18:07

1 answer

4

Using LINQ might look like this:

using System.Linq;

// gbRadioButtons - Nome do seu groupBox que contém os radio buttons.        
var anySelected = gbRadioButtons.Controls.OfType<RadioButton>().Any(x => x.Checked);

if(!anySelected) // Se nenhum foi selecionado
{
   MessageBox.Show("Por favor, selecione um item.");
}

In the code above, I am using LINQ to iterate over all items of type RadioButton within its GroupBox and look for if at least some RadioButton was selected and write this value in the anySelected variable.

    
05.10.2017 / 18:39