[英]Cycle single record with Tab key
I'm trying to get a certain tab
& enter
key behaviour in the datagridview. 我正在尝试获取特定tab
并在datagridview中enter
关键行为。 Once the focus is on a cell in the datagridview, I'd like the following: 一旦将焦点放在datagridview中的单元格上,我将需要以下内容:
TAB
- cycles through cells in the row, without going to the next row after the last cell in the row. TAB
循环浏览该行中的单元格,而无需转到该行中最后一个单元格之后的下一行。 Ie Keep cycling through the cells in an individual row. 即保持循环遍历单个行中的单元格。
ENTER
- moves to the next row. ENTER
移至下一行。
I've been looking online for solutions but they're generally not quite the behaviour I'm after, and they mostly require creating a derived DataGridView
class, which I'd prefer to avoid if possible. 我一直在网上寻找解决方案,但是它们通常不符合我的要求,它们大多需要创建派生的DataGridView
类,如果可能的话,我希望避免此类。
I also want to avoid triggering the RowLeave
event, because I'm using that to validate & then accept/reject any cell changes made in that row - hence the conscious ENTER
key press to move away from the row and trigger its validation & persistence. 我还想避免触发RowLeave
事件,因为我正在使用它来验证然后接受/拒绝该行中进行的任何单元格更改-因此,有意识的ENTER
键按下以离开该行并触发其验证和持久性。
I've implemented a solution to this now, and thought I should update here with detail of the particular approach I took. 我现在已经实现了对此的解决方案,并认为我应该在此处更新我所采用的特定方法的详细信息。
I put in DataGridView
's OnKeyDown
event something along the lines of: 我将DataGridView
的OnKeyDown
事件放入以下内容:
if (e.KeyCode == Keys.Tab)
{
if (dataGrid.CurrentCell.ColumnIndex == dataGrid.Columns.Count - 1)
{
dataGrid.CurrentCell = dataGrid[1,dataGrid.CurrentCell.RowIndex];
}
}
Seems to do the trick. 似乎可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.