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

牧云@^-^@ 提交于 2020-01-17 03:41:25

问题


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

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.

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


回答1:


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

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.


来源:https://stackoverflow.com/questions/18570802/how-to-check-a-checkbox-created-with-vbs-datagridviewcheckboxcolumn-on-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!