(datagridview)如果单击列表头,全选.(第一列为复选框)

来源:互联网 发布:db2如何连接数据库 编辑:程序博客网 时间:2024/05/09 14:49
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1   )//如果单击列表头,全选.
            {
                int i;
                for (i = 0; i < this.dataGridView1.RowCount; i++)
                {
                    this.dataGridView1.EndEdit();//结束编辑状态.
                    string re_value = this.dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString();
                    this.dataGridView1.Rows[i].Cells[0].Value   = "true";//如果为true则为选中,false未选中
                    this.dataGridView1.Rows[i].Selected = true;//选中整行。
                 
                }  
            }
        }