简体   繁体   English

复选框在VB.Net表单中不起作用

[英]Checkbox does does not work in VB.Net form

I have two checkboxes for two groupboxes to enable visibility or invisibility of each one at a time but somehow one is working( chboNew ) the other one( chboIssue ) doesn't! 我有两个checkboxes两个groupboxes使每一次一个的可见性或不可见但不知何故,一个是工作( chboNew ),另一个( chboIssue )不! here is the code I have written for it, any help would be appreciated: 这是我为此编写的代码,任何帮助将不胜感激:

Private Sub chboIssue_CheckStateChanged(sender As Object, e As EventArgs) Handles chboIssue.CheckStateChanged
    If chboIssue.Checked = True Then
        gbIssueSearch.Visible = True
        gbNewSearch.Visible = False
        chboNew.Checked = False
    ElseIf chboIssue.Checked = False Then
        gbIssueSearch.Visible = False
    End If
End Sub

Private Sub chboNew_CheckStateChanged(sender As Object, e As EventArgs) Handles chboNew.CheckStateChanged
    If chboNew.Checked = True Then
        gbNewSearch.Visible = True
        gbIssueSearch.Visible = False
        chboIssue.Checked = False
    ElseIf chboIssue.Checked = False Then
        gbNewSearch.Visible = False
    End If
End Sub

If user has to choose between new issue and issue search,one at a time. 如果用户必须在新问题和问题搜索之间进行选择,则一次选择一个。 Then you should use radio buttons, instead of checkbox. 然后,您应该使用单选按钮,而不是复选框。

Checkbox gives idea that user can choose both checkboxes at same time. 复选框给出了一个想法,即用户可以同时选择两个复选框。 Which in your case is not true. 在您的情况下,这是不正确的。

Changing the name of the checkboxes is not going to solve your issue. 更改复选框的名称不会解决您的问题。 I noticed that for your chboNew.CheckStateChanged event handler in your elseif clause you are checking if chboIssue is checked, whereas in your other handler for chboIssue both your if/else clauses look at chboIssue. 我注意到,对于elseif子句中的chboNew.CheckStateChanged事件处理程序,您正在检查是否已检查chboIssue,而在其他chboIssue的处理程序中,您的if / else子句均查看chboIssue。 I'm thinking that may be part of your issue. 我认为这可能是您问题的一部分。 Also, if only one of these boxes is supposed to be checked at a time, you may want to add logic to automatically uncheck the other whenever one is checked. 另外,如果一次只选中其中一个框,则可能需要添加逻辑以在选中一个框时自动取消选中另一个框。 For instance, in your chboNew handler, "If chboNew.Checked = True Then chboIssue = False", and the inverse in your chboIssue handler. 例如,在您的chboNew处理程序中,“如果chboNew.Checked = True,则chboIssue = False”,而在chboIssue处理程序中则相反。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM