VB-取消选中组框中的复选框 [英] VB - Unchecking Check Boxes in a Group Box

查看:303
本文介绍了VB-取消选中组框中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有5个群组框,每个框都充满了复选框,当我要取消选择所有复选框时(使用清除选择按钮),我使用在论坛上找到的以下代码:

Currently I have 5 group boxes all filled with checkboxes, when I want to unselect all of them (for a 'clear selection' button), I use this code that I found on a forum:

For Each CheckBox In grpbox_Hiragana
        CheckBox.checked = "false"

首先,我确定这是否是取消选中复选框的正确方法,其次, grpbox_Hiragana分组框返回以下错误:

Firstly, I'm sure if this is the correct way to unselect the checkboxes, secondly the "grpbox_Hiragana" groupbox returns the following error:


表达式的类型为'System.Windows.Forms.GroupBox',不是集合类型

Expression is of type 'System.Windows.Forms.GroupBox', which is not a collection type

如果有人可以确认这是这样做的正确方法,或者通过告诉我为什么不接受groupbox来帮助纠正错误,那就太好了。

If anyone could confirm this is the correct way of doing this/ help fix the error by telling me why the groupbox won't be accepted that would be great.

推荐答案

如果您在一个组框上都具有所有复选框,请使用以下代码:

if you have all check box on one group box use this code :

    Dim ChkBox As CheckBox = Nothing
    ' to unchecked all 
    For Each xObject As Object In Me.GroupBox1.Controls
        If TypeOf xObject Is CheckBox Then
            ChkBox = xObject
            ChkBox.Checked = False
        End If
    Next

   ' to checked all 
    For Each xObject As Object In Me.GroupBox1.Controls
        If TypeOf xObject Is CheckBox Then
            ChkBox = xObject
            ChkBox.Checked = True
        End If
    Next

或者您可以使用 CheckedListBox 控件。

Or you can use CheckedListBox Control.

这篇关于VB-取消选中组框中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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