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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

博客园 - Lucky Jack

在C#中展示嵌入的RTF文件 SQL进行排序、分组、统计的10个新技巧 select into 和 insert into select的区别 Convert的妙用 如何去除C#Strings中的空格? Format String for XML Value - Lucky Jack 如何改变字体大小呢? 如何改变字体风格? C# String小技巧 如何避免按回车键时的嗡鸣声? - Lucky Jack - 博客园 如何嵌入图片资源? Lookupedit使用小记 如何优雅的编程? 文件监视器( FileSystemWatcher) 类的使用 - Lucky Jack 反射也可以这样? - Lucky Jack - 博客园 浅谈对象的初始化顺序 也谈String.IsNullOrEmpty 经典的属性设置! 经典sql
DataGridView中回车键的妙用
Lucky Jack · 2008-04-15 · via 博客园 - Lucky Jack
 

在NET 中DataGridView 是 一个很好的控件,它提供了一个用于输入数据和显示数据的自定义表.如果你在你的程序中提供DataGridView 作为用户输入多行数据的一种方式,你或许希望重新定义一下回车键的默认操作.
假定, 当你在DataGridView中按下回车键时,这个光标会移动到相同列的 所在单元格下面的单元格(下图红色箭头所示),但是当输入多行数据时,更好的响应回车键的方式是移动到下一行的第一个单元格中(蓝色箭头).

为了做到这样,你能使用派生自DataGridView的类 :

public class Grid : DataGridView
{
然后覆写(override) 这个 OnKeyUp 受保护的方法:

protected override void OnKeyUp( KeyEventArgs e )
{
    
if (e.KeyCode == Keys.Enter)
    {
        
int currentRow = this.CurrentRow.Index;
        
if (currentRow >= 0)
            
this.CurrentCell = this.Rows[currentRow].Cells[0];
    }
    
base.OnKeyUp( e );
}

当然 , 如果你希望在已存在的DataGridView 提供这种能力, 你能简单的签名 KeyUp 事件并且执行上面相同的代码在这个事件处理程序中(event handler).