[ad_1]
您好,我已经编写了下面的代码来选择所有复选框,但我无法这样做。请帮助
我尝试过的:
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(); }
解决方案1
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 }
[ad_2]
コメント