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;
}
}
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;
}
}
相关文章推荐
- Oracle 字符集的查看和修改 分类: H2_ORACLE 2013-06-19 16:52 316人阅读 评论(0) 收藏
- 解析ASP.NET Mvc开发之删除修改数据 分类: ASP.NET 2014-01-04 23:41 3203人阅读 评论(2) 收藏
- 修改Linux中的用户名 分类: B3_LINUX 2014-07-24 11:40 440人阅读 评论(0) 收藏
- 基于gnu-arm-linux的LPC2220的简单工程模板 分类: 嵌入式开发学习 2014-08-04 21:52 397人阅读 评论(0) 收藏
- MyEclipse修改页面模板(JSP和HTML等) 分类: WEB项目应用 2010-01-31 00:03 698人阅读 评论(1) 收藏
- ubuntu 下修改root密码 分类: ubuntu 2013-04-14 13:58 291人阅读 评论(0) 收藏
- Viola Jones Face Detector 分类: 计算机视觉(转载) 2014-08-04 11:07 139人阅读 评论(0) 收藏
- hi3531 SDK 编译 kernel, 修改 参数 分类: arm-linux-Ubuntu HI3531 2014-05-07 11:23 1120人阅读 评论(0) 收藏
- hi3531 SDK 编译 kernel, 修改 参数 . 分类: HI3531 arm-linux-Ubuntu 2014-06-18 08:54 773人阅读 评论(0) 收藏
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
- 修改类属性 分类: divide into python 2013-11-06 16:48 236人阅读 评论(0) 收藏
- 修改xml中的字段值 分类: xml python 小练习 2014-03-13 12:00 276人阅读 评论(0) 收藏
- Linux环境下修改MySQL端口方法: 分类: database ubuntu 测试 2014-02-25 16:42 3334人阅读 评论(0) 收藏
- linux 修改系统时间 分类: ubuntu 2014-07-28 12:04 209人阅读 评论(0) 收藏
- DataGridView列头checkbox 分类: .NET 2013-03-13 14:09 1343人阅读 评论(0) 收藏
- ubuntu修改密码 分类: ubuntu学习 2013-06-14 16:21 723人阅读 评论(0) 收藏
- 修改mysql字符集编码 分类: 数据库 2010-07-27 11:02 1424人阅读 评论(0) 收藏
- winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏
- SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏