问题
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