单个复选框以检查Visual Basic中的多个复选框 [英] Single checkbox to check multiple checkboxes in Visual Basic

查看:68
本文介绍了单个复选框以检查Visual Basic中的多个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨好的codeproject人,我创建了一个groupBox1,其中包含39个可以单独检查的复选框,我创建了一个gropuBox2,其中包含一个名为Check All的复选框,我想要的是全部检查 选中复选框后,将选中所有39个复选框,当取消选中全部检查时,所有39个复选框也将被取消选中,有人可以帮忙吗?非常感谢。

Hi good people of codeproject, I have created a groupBox1 which contains 39 checkboxes which can be checked individually, and I have created a gropuBox2 which contains single check box called "Check All", What I want is when the "Check All" check box is checked all the 39 checkboxes will be selected and when the "Check All" is unchecked all 39 checkboxes will be unchecked also, Can someone please help? Thank you very much.

推荐答案

我认为最好的解决方案是



I think the best solution for this will be

private void CheckUncheck()
       {
           foreach (CheckBox chk in groupBox1.Controls)
           {
               chk.Checked = chk.Checked == false;
           }
       }


参考: VB - 取消选中组框中的复选框 [ ^ ]


第一个解决方案:

First solution :
Private Sub cbxAll_CheckedChanged(sender As Object, e As System.EventArgs) Handles cbxAll.CheckedChanged                                                                      
    If cbxAll.Checked = True Then
        cbx01.Checked = True
        cbx02.Checked = True
        ' 3 .. 38
        cbx39.Checked = True
    Else
        cbx01.Checked = False
        cbx02.Checked = False
        ' 3 .. 38
        cbx39.Checked = False
    End If
End Sub





第二个解决方案:
带有相同事件的
复选框(全部)对表格的所有控件进行循环,以匹配其他39的名称,如果你在其中命名的话一种正确的方法,你可以修改他们的财产(.Checked =真/假)。



希望帮助



Second solution :
with the same event on checkbox(All) make a loop over all control of the form that match the name of the other 39 , if you name them in a proper way you can modify their property (.Checked = True/False).

Hope help


这篇关于单个复选框以检查Visual Basic中的多个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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