如何设置和获取datagridview中checkbox的选中项

2024-08-10 23:40:33
推荐回答(1个)
回答1:

(以下为转贴) private void PrintInFo() {try{int count = 0; //用于保存选中的checkbox数量 //DG_List为datagridview控件 for (int i = 0; i < DG_List.RowCount; i++){if (DG_List.Rows[i].Cells [0].EditedFormattedValue.ToString() == "True") //这里判断复选塌升框是否选中{count++;}}if (count == 0){MessageBox.Show("请至少选择一条数据!", "提示");return;}else{if (MessageBox.Show(this, "您要更新数据么?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information).ToString() == "Yes"){for (int i = 0; i < count; i++){ps.Pexcute(" update cf_prj_certi set FIsPrint='"+number+"' where fid='" + DG_List.Rows[i].Cells["fnn"].Value.ToString() + "'"); //执行世乱SQL}} else{return;}}} catch (Exception ex){MessageBox.Show(ex.ToString()); } this.ShowInfo(); //重新绑定datagridview} ========================================= 点击dataGridView1事件中的CellMouseClick 事件 private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e){if(e.ColumnIndex==6){dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = true;}}********************设置datagridview列表中checkbox列的选中状团返老态********************************* foreach (DataGridViewRow dgvr in this.dgvList.Rows){dgvr.Cells["chbox"].Value = this.chboxSel.Checked;// 此为单独的全选框}