如何选择datagridview中的所有复选框 [英] How to select all checkboxes in datagridview
本文介绍了如何选择datagridview中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我已经写了belw代码来选择所有复选框但我无法这样做。请帮助
我尝试过:
hi i have written belw code to select all checkboxes but i am unable to do so.please help
What I have tried:
CheckBox HeaderCheckBox=null;
bool IsHeaderCheckBoxClicked=false;
private void AddHeaderCheckBox()
{
HeaderCheckBox= new CheckBox();
HeaderCheckBox.Size=new Size(15,15);
//add check ti DGV
this.dataGridView1.Controls.Add(HeaderCheckBox);
}
private void HeaderCheckBoxClick(CheckBox HCheckBox)
{
IsHeaderCheckBoxClicked =true;
foreach(DataGridView Row in dataGridView1.Rows)
(DataGridViewCheckBoxCell)Row.CellStateChanged["chk"].value=HCheckBox.Checked;
}
public void MainFormLoad(object sender, EventArgs e)
{
AddHeaderCheckBox();
}
推荐答案
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell) row.Cells[0];
chk.Value = !(chk.Value == null ? false : (bool) chk.Value); //because chk.Value is initialy null
}
这篇关于如何选择datagridview中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文