c# winform中如何控制焦点。新人求教。

如何实现光标在文本框的,数据库的表格在按上下键时可以移动。就是下面这种情况。
图片说明

 private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Down)
            {
                this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index + 1 > this.dataGridView1.Rows.Count ? this.dataGridView1.Rows.Count - 1 : this.dataGridView1.CurrentRow.Index + 1].Selected = true;
            }

            if (e.KeyData == Keys.Up)
            {
                this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index - 1 < 0 ? 0 : this.dataGridView1.CurrentRow.Index - 1].Selected = true;
            }
        }

通过keycode获取按键,然后让datagridview的选中行索引改变。
http://blog.csdn.net/youyoulg/article/details/39120669

通过keycode获取按键,然后让datagridview的选中行索引改变。
http://blog.csdn.net/youyoulg/article/details/39120669

图片说明

拦截KeyPress这类事件,通过事件中的按键信息来判定,如果是KeyUp或者KeyDown,就做移动处理,然后将按键设定为0