简体   繁体   English

C#DataGridView:覆盖keydown事件

[英]C# DataGridView : override keydown events

i am working with DataGridView trying to provide specific utility to my user... 我正在使用DataGridView尝试为我的用户提供特定的实用程序...

what i want to do is when some key is presses instead of the normal function that the key was supposed to perform like updown arrows and page up down keys etc i want to stop the default action 我想要做的是当一些键是按下而不是键应该执行的正常功能,如上升箭头和向上翻页键等我想要停止默认操作

like when on a selected row, datagrid in selectfullrow , when down arrow is press it shouldn't change the row selection or goto the next row 比如在选定的行上, selectfullrow datagrid,当按下向下箭头时它不应该更改行选择或转到下一行

You should handle the KeyDown event and set the e.Handled to true to disable the default action: 您应该处理KeyDown事件并将e.Handled设置为true以禁用默认操作:

    private void dataGridView1_KeyDown(object sender, KeyEventArgs e) {
        e.Handled = e.KeyCode == Keys.Down;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM