如何为我的Datagridview创建Checkall / Uncheckall复选框按钮 [英] How Do I Create A Checkall/Uncheckall Checkboxes Button For My Datagridview

查看:99
本文介绍了如何为我的Datagridview创建Checkall / Uncheckall复选框按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为我的datagridview创建一个checkall / uncheckall复选框按钮,该按钮具有复选框列

How do i create a checkall/uncheckall checkboxes button for my datagridview that has a checkbox column

推荐答案

如果确实存在单独的解决方案1的简单替代方法表单上的按钮而不是列标题...



假设按钮名为ButtonSelect,其中带有复选框的列名为CheckBoxColumn。



将按钮的文本初始化为全选,例如
A simple alternative to Solution 1 if there is indeed a separate button on your form rather than the column header ...

Assume the button is named "ButtonSelect" and the column with the checkbox in it is named "CheckBoxColumn".

Have the text of the button initialised to "Select All" e.g.
ButtonSelect.Text = "Select All"

然后添加以下代码

Private Sub ButtonSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSelect.Click

    Dim newValue As Boolean
    Dim newText As String

    If ButtonSelect.Text = "Select All" Then
        newText = "Unselect All"
        newValue = True
    Else
        newText = "Select All"
        newValue = False
    End If

    For Each dr As DataGridViewRow In DataGridView1.Rows
        dr.Cells("CheckBoxColumn").Value = newValue
        ButtonSelect.Text = newText
    Next
End Sub



如果发生这种情况,请道歉在解决方案1的视频链接中 - 我只是无法让自己观看整个事情。


Apologies if this is what happens in the video link from solution 1 - I just couldn't bring myself to watch the whole thing.


试试这些链接 -

切换DataGridView列内所有CheckBox的状态 [ ^ ]

视频 [ ^ ]
Try these links -
Toggling the States of all CheckBoxes Inside a DataGridView Column[^]
Video[^]


这篇关于如何为我的Datagridview创建Checkall / Uncheckall复选框按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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