winform下gridview中的checkbox列,实现点击列头的checkbox来完成全选和不全选 在winform下,gridview的checkbox列要实现全选和不全选,可以在该列的列头加个checkbox来实现吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if (this.chkAllChecked.Checked) { for (int count = 0; count < this.dgvCommon.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"]; this.dgvCommon.Rows[count].Cells["chkClient"].Value = true; this.dgvCommon.SelectAll(); } } else { for (int count = 0; count < this.dgvCommon.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"]; this.dgvCommon.Rows[count].Cells["chkClient"].Value = false; this.dgvCommon.ClearSelection(); } }以下是行的全选代码,只需红色部分就可以 private void checkBoxAll_CheckedChanged(object sender, EventArgs e) { if (checkBoxAll.Checked) { foreach (DataGridViewRow myDgvr in dataGridView1.Rows) { myDgvr.Cells["Xuan"].Value = 1; } } else { foreach (DataGridViewRow myDgvr in dataGridView1.Rows) { myDgvr.Cells["Xuan"].Value = 0; } } } 错了:用下面这个.if (this.你要点击的checkbox.Checked) { for (int count = 0; count < this.datagridview1.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["你的checkbox"]; this.datagridview1.Rows[count].Cells["你的checkbox"].Value = true; } } else { for (int count = 0; count < this.datagridview1.Rows.Count; count++) { DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["你的checkbox"]; this.datagridview1.Rows[count].Cells["你的checkbox"].Value = false; } } 忘记说了,dataGridView1 中那个checkBox的TrueValue为1,FalseValue为0 我是想在checkbox的列头上也加个checkbox,就像网页上那样的效果,勾上列头的checkbox就全选,下面列中的,不够下面单元格的也都不选啊~ 即时通讯软件:在聊天界面内增加对对方说话内容进行修改的方式 固定区域内按定距绘制点 急...求助 编写函数.使用FOR循环 计算二违数组最大直和下标 picturebox通过流加载gif图片后,图片没有动画效果 如何把望站发布出来? C#如何多次连接数据库啊? 关于进程的调用和参数传递 菜鸟正则问题在线等!!!!!!! 高分求救,分不够在+ 如何调用VB写的DLL? ShowDialog()得窗口关闭问题 怎么更改winform自带控件样式 C# 操作两个数据库 问题
if (this.chkAllChecked.Checked)
{
for (int count = 0; count < this.dgvCommon.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"];
this.dgvCommon.Rows[count].Cells["chkClient"].Value = true;
this.dgvCommon.SelectAll();
}
}
else
{
for (int count = 0; count < this.dgvCommon.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["chkClient"];
this.dgvCommon.Rows[count].Cells["chkClient"].Value = false;
this.dgvCommon.ClearSelection();
}
}
以下是行的全选代码,只需红色部分就可以
private void checkBoxAll_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxAll.Checked)
{
foreach (DataGridViewRow myDgvr in dataGridView1.Rows)
{
myDgvr.Cells["Xuan"].Value = 1;
}
}
else
{
foreach (DataGridViewRow myDgvr in dataGridView1.Rows)
{
myDgvr.Cells["Xuan"].Value = 0;
}
}
}
{
for (int count = 0; count < this.datagridview1.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["你的checkbox"];
this.datagridview1.Rows[count].Cells["你的checkbox"].Value = true;
}
}
else
{
for (int count = 0; count < this.datagridview1.Rows.Count; count++)
{
DataGridViewCheckBoxCell cbh = (DataGridViewCheckBoxCell)this.dgvCommon.Rows[count].Cells["你的checkbox"];
this.datagridview1.Rows[count].Cells["你的checkbox"].Value = false;
}
}
忘记说了,dataGridView1 中那个checkBox的TrueValue为1,FalseValue为0