2

我正在使用 Infragistics UltraWinGrid v9.1。我想允许用户在单元格中输入数字数据,按Enter 键,然后将焦点放在下面的单元格上,就像您在 Excel 中看到的那样。看起来 KeyUp 事件可能比 KeyPressed 事件更好,但是我一直抛出一个异常,即使我从完整网格的顶部开始,我已经超出了 UltraWinGrid 的范围。这是我尝试过的代码:

    private void ugrid_KeyUp(object sender, KeyEventArgs e)
    {
        UltraGrid grid = (UltraGrid)sender;

        if (e.KeyCode == Keys.Enter)
        {
            // Go down one row
            UltraGridCell cell = grid.ActiveCell;
            int currentRow = grid.ActiveRow.Index;
            int col = cell.Column.Index;
            grid.Rows[currentRow + 1].Cells[grid.ActiveCell].Activate();
        }
    }

我希望这会使单元格在同一列但下面的一行成为调用 grid.Rows[currentRow + 1].Cells[grid.ActiveCell].Activate(); 的活动单元格;

而是抛出异常:

Infragistics2.Shared.v9.1.dll 中发生了“System.IndexOutOfRangeException”类型的异常,但未在用户代码中处理附加信息:索引超出了数组的范围。

由于我在第 0 行并且存在第 1 行,这对我来说是一个惊喜。currentRow 和 col 的值分别为 0 和 28。什么是更好的方法?顺便说一句,我可以在下面的单元格中再次执行此操作,其中值是 currentRow = 1 和 col = 28。抛出相同的异常。

4

4 回答 4

6

有人在 Infragistics 论坛上回答了我的问题...

    private void ugrid_KeyUp(object sender, KeyEventArgs e)
    {
        var grid = (UltraGrid)sender;

        if (e.KeyCode == Keys.Enter)
        {
            // Go down one row
            grid.PerformAction(UltraGridAction.BelowCell);
        }
    }
于 2010-02-15T16:25:34.613 回答
2

我不知道我所说的是否也适用于 v9.1,但您也可以执行以下操作:

yourGrid.KeyActionMappings.Add(new GridKeyActionMapping(Keys.Enter, UltraGridAction.BelowCell, 0, UltraGridState.Row, SpecialKeys.All, 0));
于 2012-02-20T16:29:28.713 回答
1
 private void ulGrvProducts_KeyUp(object sender, KeyEventArgs e)
        {

            UltraGrid grid =  (UltraGrid)sender;

            if (e.KeyCode == Keys.Enter)
            {
                 //Go down one row
                grid.PerformAction(UltraGridAction.BelowCell);
            }
        }
于 2012-11-22T17:44:57.597 回答
0

使用后grid.PerformAction(UltraGridAction.BelowCell),活动行将更改,但下一个单元格不处于编辑模式。

于 2013-04-18T11:29:46.087 回答