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

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;//选中整行。
                 
                }  
            }
        } 

posted on 2007-01-30 11:26  玄新  阅读(1048)  评论(0编辑  收藏  举报

导航