DataGridView,如何捕获单元格的KeyPress事件以捕获Enter/Up/Down键 [英] DataGridView, how to capture a cell's KeyPress event for Capturing Enter/Up/Down key

查看:117
本文介绍了DataGridView,如何捕获单元格的KeyPress事件以捕获Enter/Up/Down键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在datagridview中捕获单元格的按键事件.
我正在使用以下代码,但是通过此代码,无法捕获Enter/Down键.

How to capture the cell''s keypress event in datagridview.
i am using following code, but by this code Enter/Down keys are not capturing.

void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
        {
            TextBox txtbox = e.Control as TextBox;
            if (txtbox != null)
            {
                txtbox.KeyPress += new
KeyPressEventHandler(txtbox_KeyPress);
            }
        }

        void txtbox_KeyPress(object sender, KeyPressEventArgs e)
        {
            MessageBox.Show(e.KeyChar.ToString());
        }



如何在数据网格视图的单元格中捕获Enter/Down/Up键?
请帮助



What to do for capturing Enter/Down/Up key in the cell of data grid view?
Please Help

推荐答案

使用PreviewKeyDown事件代替Keypress事件.
Use PreviewKeyDown event instead of Keypress event.


这篇关于DataGridView,如何捕获单元格的KeyPress事件以捕获Enter/Up/Down键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆