DataGridView 中CheckBox 获取状态
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView3_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (this.dataGridView3.IsCurrentCellDirty) { this.dataGridView3.CommitEdit(DataGridViewDataErrorContexts.Commit); string colName = this.dataGridView3.CurrentCell.OwningColumn.Name; if(colName.Equals("escStatusFlag")) { // 如果CheckBox已选中,则在此处继续编写代码 bool selectValue = Convert.ToBoolean( dataGridView3.CurrentRow.Cells["escStatusFlag"].EditedFormattedValue); string Esclrwid =dataGridView3.CurrentRow.Cells["升级编号"].Value.ToString(); UpdateEscStatus(Esclrwid,selectValue); } } } /// <summary> /// 依据Checkbox 控件的状态,更新升级状态处理中 /// </summary> /// <param name="Esclrwid"></param> /// <param name="escStatusFlag"></param> private void UpdateEscStatus(string Esclrwid, bool escStatusFlag) { try { string sUpdate = string.Empty; if (escStatusFlag) { sUpdate = string.Format(" UPDATE dbo.CRESCULATN SET escStatusFlag ='{0}' WHERE esclrwid ='{1}'", Common.EscStatus.外部处理中升级, Esclrwid); } else { sUpdate = string.Format(" UPDATE dbo.CRESCULATN SET escStatusFlag ='{0}' WHERE esclrwid ='{1}'", Common.EscStatus.非外部处理中升级, Esclrwid); } gs.ExecuteCmd(sUpdate); } catch(Exception ex) { MessageBox.Show("更新处理中升级状态失败:" + ex.Message); } }