日期:2014-05-18 浏览次数:21656 次
int k = dataGridView.RowCount; if (k != 0) { for (int i = 0; i < k; i++) dataGridView.Rows[i].Cells[你的check索引].Value = true;//全选 } ///////////////// int k = dataGridView.RowCount; if (k != 0) { this.dataGridView.EndEdit();//结束编辑状态. for (int i = 0; i < k; i++) { if (Convert.ToBoolean(dataGridView.Rows[i].Cells[你的check索引].Value) == true) dataGridView.Rows[i].Cells["Removed"].Value = false;//全不选 else continue; } }
------解决方案--------------------
你的DataGridViewCheckBoxColumn应该是非绑定数据源吧
添加时属性设置下就好了,ColumnType=DataGridViewCheckBoxColumn
ReadOnly=false
如果还不行的话
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1 && e.RowIndex != -1)
{
if (Convert.ToBoolean(dataGridView.Rows[e.RowIndex].Cells[“Removed”].Value) == false)
dataGridView.Rows[e.RowIndex].Cells[“Removed”].Value = true;
else
dataGridView.Rows[e.RowIndex].[“Removed”]Value = false;
}
}
------解决方案--------------------
private void btnSelectAll_Click(object sender, EventArgs e) { DataTable myTable = new DataTable(); myTable.Columns.Add().ColumnName = "str"; for (int i = 0; i < 5; i++) { DataRow dr = myTable.NewRow(); dr["str"] = "1"; myTable.Rows.Add(dr); } this.dataGridView2.DataSource = myTable; this.dataGridView2.Columns["str"].Visible = false; if (dataGridView2.Rows.Count != 0) { for (int i = 0; i < this.dataGridView2.Rows.Count - 1; i++) { this.dataGridView2.Rows[i].Cells[0].Value = true; } } }
------解决方案--------------------
楼主是不是勾选了某个checkbox,但是运行程序的时候cells。value没有改变呀?
------解决方案--------------------
http://www.guanmingle.com/index.php/datagridviewsort/
这里的解决办法应该对你有帮助
------解决方案--------------------
http://www.guanmingle.com/index.php/datagridviewsort/
------解决方案--------------------
直接设置该行该cell的value值为true或false
别忘加上this.dataGridView.EndEdit();