您的位置:首页 > 其它

winform DataGridView双击修改单元格的值 分类: DataGridView 2014-08-04 19:39 150人阅读 评论(0) 收藏

2014-08-04 19:39 961 查看
定义全局变量

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐