定义全局变量
string abcmycode = "";//当前行自编号
bool tf = false;//是否双击
//双击可编辑
private void dgvOutClassVerify_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
if (dgvOutClassVerify.Rows.Count > 0) {
abcmycode = dgvOutClassVerify.CurrentRow.Cells["MainTop_Mycode"].Value.ToString();
dgvOutClassVerify.CurrentRow.Cells["MainTop_Mycode"].ReadOnly = false;
tf = true;
}
}
private void dgvOutClassVerify_CellValidated(object sender, DataGridViewCellEventArgs e) {
try {
if (tf == true) {
tf = false;
if (dgvOutClassVerify.Rows.Count > 0) {
int abcid = Convert.ToInt32(dgvOutClassVerify.CurrentRow.Cells["MainTop_ID"].Value.ToString());
string mycodes = dgvOutClassVerify.CurrentRow.Cells["MainTop_Mycode"].Value.ToString();
if (abcmycode != mycodes) {
if (mycodes.Equals("")) {
PublicClass.ShowMessage("自编号不能为空!");
dgvOutClassVerify.CurrentRow.Cells["MainTop_Mycode"].Value = abcmycode;
return;
}
//验证语句
//----------------------------
//更新语句
string cbasql = "update T_OutIn_MainTop set MainTop_MyCode='" + mycodes + "' where MainTop_ID= " + abcid;
int nn = DataAccess.ExecuteNonQuery(cbasql, false, null);
if (nn > 0) {
dgvOutClassVerify.CurrentRow.Cells["MainTop_MyCode"].ReadOnly = true;
PublicClass.ShowMessage("自编号修改成功!");
return;
}
}
}
}
} catch (Exception ex) {
PublicClass.ShowMessage(ex.Message);
return;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。