How do I force user to select a Radio Button within the GroupBox.
Image example below
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.