vb.net 如何在运行时检查使用 VB 的 DataGridViewCheckBoxColumn 创建的复选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18570802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:54:11  来源:igfitidea点击:

How to check a checkbox created with VB's DataGridViewCheckBoxColumn on Runtime

vb.netvisual-studiovisual-studio-2008datagridview

提问by dorothy

I wanted to check/tick a column created with DataGridViewCheckBoxColumn on runtime.

我想在运行时检查/勾选使用 DataGridViewCheckBoxColumn 创建的列。

here's a snippet of my code;

这是我的代码片段;

Dim checkCol As DataGridViewCheckBoxColumn = New DataGridViewCheckBoxColumn()
DataGridView1.Columns.Add(checkCol)

After I added this column, I wanted to check/tick some of these checkboxes on start up of the VB application.

添加此列后,我想在 VB 应用程序启动时选中/勾选其中一些复选框。

How do I do that? Do I have to make use of some of the methods from Checkbox Class? thanks

我怎么做?我是否必须使用 Checkbox Class 中的某些方法?谢谢

回答by varocarbas

A CheckBoxaccepts two values: True(checked) or False(unchecked). You can set/get the values of any cell of you DataGridViewat runtime by doing:

ACheckBox接受两个值:(True选中)或False(未选中)。您可以DataGridView通过执行以下操作在运行时设置/获取您的任何单元格的值:

DataGridView1(0, 0).Value = True 'Checking the CheckBox in the first row/first column 
Dim isChecked As Boolean = DirectCast(DataGridView1(0, 2).Value, Boolean) 'Getting the check status of the third row/first column.