未在GroupBox中选择RadioButton [英] RadioButton not selected in a GroupBox

查看:155
本文介绍了未在GroupBox中选择RadioButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个Windows窗体,其中在GroupBox中有一组4个单选按钮.我如何确保每次用户默认情况下都必须至少选择1个单选按钮(在Form_Load上不应选择任何默认单选按钮).该方案是,如果我继续提交表单而不选择GroupBox中的任何单选按钮,那么应该有一个验证信息,说您没有选择任何选项"
谢谢,
Tushar.

Hi,

I am developing a windows forms in which i have a set of 4 radio buttons within a GroupBox. How do i ensure that everytime the user must by default select at least 1 radio button (no default radio button should not be selected on Form_Load). The scenario is if i go ahead and Submit the form without selecting any of the radio buttons in the GroupBox then there should be a validation saying "You did not select any options"
Thanks,
Tushar.

推荐答案

可以使用If语句完成.我假设表单上的某处有一个提交它的按钮.在该按钮中进行检查.如果未选中所有单选按钮,则不要执行保存并退出的代码.

像这样的东西:
This can be done with an If statement. I''m assuming somewhere on the form you have a button that submits it. In that button do a check. If all of the radio buttons are unchecked, then do not execute the code that saves and exits.

Something like this:
Dim boolUserMissedDataEntry as Boolean = False 'Track if user missed entering data so that later you know whether to skip the save or not

If Not rdbOne.Checked AndAlso Not rdbTwo.Checked AndAlso Not rdbThree.Checked AndAlso Not rdbFour.Checked Then
   'All of the radio buttons are unchecked, so display the error message
   MessageBox.Show("You did not select any options.")
   boolUserMissedDataEntry = True 'User missed entering data
End If

If Not boolUserMissedDataEntry Then
   'Code to save form and exit would go here
End If


这篇关于未在GroupBox中选择RadioButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆