惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - 缤纷夏日

文件分割合并DOS版 安装vs2017后,RDLC 报表定义具有无法升级的无效目标命名空间 frp+TeamViewer 完美解决TeamViewer5分钟商业提醒 TortoiseGit版本库中某个文件显示问号或叹号的问题解决办法 vs2012调试时,抛出异常的等待时间很慢,原来是QQ电脑管家搞的鬼。 wordpress4.4+版本自动生成一个768w像素缩略图的解决办法 vs2012 与 win7 不兼容的问题 c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单。 自制《要塞:十字军东征》无限金钱修改器 ms Sql 数据库出现 “提供的统计信息流已损坏”的解决办法。 C#+Midi 模拟各种乐器演奏 如何让DataGridView根据数据“0”或“1”等值显示为“是”或“否”(复选框的使用) DataGridView 显示和隐藏DataGridViewButtonCell按钮的办法 文件隐藏助手,将一个压缩文件隐藏到图片中 如何让DataGridview控件自动滚动到指定的行或列 为Winform程序中DataGridView控件增加自动显示行号功能 在Excel Vba程序中自制进度条,显示实时进度信息 地下城守护者2 无限魔法修改器 缤纷影视系统3.0源码开放
Winform中的DataGridView控件内容自动保存
缤纷夏日 · 2010-10-13 · via 博客园 - 缤纷夏日

DataGridView控件在Winform程序中使用相当的普遍,如何能让其输入即保存,而不用另增加一个“保存”按钮呢?

经研究,终于找到解决办法:

在DataGridView的RowValidated事件中增加代码以下代码

//获取该行绑定数据
DataRowView row = (DataRowView)gvProduct.Rows[e.RowIndex].DataBoundItem;
//若数据未改动,则返回
if (row.Row.RowState == DataRowState.Unchanged) return;
//执行SQL更新数据
string sql = "update t_product set ipri={0},opri={1} where productNO='{2}'";
DBsql.ExecuteNonQuery(
string.Format(sql, row["ipri"], row["opri"], row["productNO"]));
//告知DataGridView,已接受改动,下次校验时行状态为DataRowState.Unchanged
row.Row.AcceptChanges();

RowValidated事件为行校验完成事件,当然你也可以在单元格校验事件中进行保存。

 完成这样的效果,使程序变得傻瓜化。

就这是软件易用性的典范.