如何在按下Enter键时更改DataGridView中的选定单元格 [英] How to change the selected cell in the DataGridView when pressing Enter

查看:77
本文介绍了如何在按下Enter键时更改DataGridView中的选定单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个DataGridView,当按下Enter 按钮时,我想将选择更改为另一个单元格,

我使用了Key_Down事件处理程序,但是在单元格处于编辑模式时按Enter 时它不起作用.

预先感谢,
:)

Hi all,

I have a DataGridView, when pressing Enter button I want to change selection to another cell,

I used the Key_Down event handler but it didn''t work when pressing Enter when the cell is in edit mode.

Thanks in advance,
:)

推荐答案

使用DataGridView.CurrentCell属性:^ ]

Use the DataGridView.CurrentCell property: MSDN[^]

int row = dataGridView1.CurrentCell.RowIndex;
int col = dataGridView1.CurrentCell.ColumnIndex;
dataGridView1.CurrentCell = dataGridView1[col, row + 1];

(您将必须添加错误检查等,但这是执行此操作的一般方法.)

(You will have to add error checking and so forth, but that''s the general way to do it.)


这篇关于如何在按下Enter键时更改DataGridView中的选定单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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