1
Using LINQ
can stay 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’m using LINQ
to iterate over all type items RadioButton
within your GroupBox
and look if at least some RadioButton
was selected and write this value to the variable anySelected
.
Couldn’t put a preselected one?
– Marconi
It would be interesting too, but if there was the possibility of playing an alert if the user forgot.
– Danillo Victtor
@Danillovictor Did my answer solve your problem? If yes, consider marking it as accepted.
– MurariAlex
Ready, marked!
– Danillo Victtor