Vb.net 验证单选按钮组

Vb.net 验证单选按钮组,vb.net,validation,Vb.net,Validation,如何验证是否选中了groupbox中的至少一个单选按钮?我正在验证所有文本控件是否像这样正确填充 For Each ctrl As Control In Me.Controls If TypeOf ctrl Is TextBox Then If ctrl.Text = "" Then MessageBox.Show("Please enter information in " & ctrl.Name,

如何验证是否选中了groupbox中的至少一个单选按钮?我正在验证所有文本控件是否像这样正确填充

        For Each ctrl As Control In Me.Controls
        If TypeOf ctrl Is TextBox Then
            If ctrl.Text = "" Then
                MessageBox.Show("Please enter information in " & ctrl.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If
        End If
对于单选按钮是否有类似的方法,因为我似乎找不到逻辑方法来完成此操作。

您可以使用LINQ:


当您布局表单时,您可以将一个设置为默认值,用户不能取消选中任何,并且您根本不必执行任何检查。否则,复选框将在GroupBox中找到。控件不是我。当然是控件!我想得太多了。
Dim uncheckedRadios = From radio In Me.groupbox1.Controls.OfType(Of RadioButton)()
                      Where Not radio.Checked
                      Select radio.Name
Dim anyUnchecked As Boolean = uncheckedRadios.Any()

If anyUnchecked Then
    Dim uncheckedNames = String.Join(",", uncheckedRadios)
    MessageBox.Show("Please check all radio-buttons, these are not checked: " & uncheckedNames, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return
End If