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;//选中整行。 } } }
转载于:https://www.cnblogs.com/hengbo/archive/2008/11/26/2232517.html
相关资源:DataGridView的列头筛选功能,以及列头带checkbox