如何在datagridview中按下向下键移动到窗体中的下一个控件? [英] how to move to next control in the form on pressing of down key in datagridview?

查看:73
本文介绍了如何在datagridview中按下向下键移动到窗体中的下一个控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在datagridview中按下向下键移动到窗体中的下一个控件?

how to move to next control in the form on pressing of down key in datagridview??

推荐答案

你可能会通过这样做来惹恼你的用户但这会work
You will probably annoy your users by doing this but this would work
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Down)
    {
        textBox1.Focus(); // Replace this with the control you want
        e.Handled = true;
    }
}



注意使用 e.Handled = true; 停止由DataGridView处理的按键(并且焦点返回到它)。



我会建议您检查您在DGV中的行踪,并且只有移动到下一个控件如果用户在最后一行,例如


Note the use of e.Handled = true; to stop the key press being processed by the DataGridView (and focus returning to it).

I would advise checking whereabouts you are in the DGV and only move to the next control if the user is on the last row e.g.

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode != Keys.Down || dataGridView1.CurrentCell.RowIndex != dataGridView1.Rows.Count - 1) return;

    textBox1.Focus();
    e.Handled = true;
}


这篇关于如何在datagridview中按下向下键移动到窗体中的下一个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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