C# 在c中使用xeed datagrid将焦点更改为下一个单元格#

C# 在c中使用xeed datagrid将焦点更改为下一个单元格#,c#,datagrid,xceed,C#,Datagrid,Xceed,我是C语言编程新手。我需要改变一下我们的项目。基本上我们使用的是XeedDataGrid,它有4列。数据与集合对象绑定,并通过DB调用动态更新。我的问题共4列,1列可编辑。当用户在此列中进行更改并按enter键时,需要在编辑模式下将焦点更改为同一列中的下单元格。下面是我正在编写的KeyUp事件。更改此列并按enter键后,焦点将转到下一行,但编辑模式不会转到下一个单元格,而是停留在已编辑的同一单元格上 private void _dataGrid_KeyUp(object sender, Sys

我是C语言编程新手。我需要改变一下我们的项目。基本上我们使用的是XeedDataGrid,它有4列。数据与集合对象绑定,并通过DB调用动态更新。我的问题共4列,1列可编辑。当用户在此列中进行更改并按enter键时,需要在编辑模式下将焦点更改为同一列中的下单元格。下面是我正在编写的KeyUp事件。更改此列并按enter键后,焦点将转到下一行,但编辑模式不会转到下一个单元格,而是停留在已编辑的同一单元格上

private void _dataGrid_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
    _dataGrid.EndEdit();
    int currentRow = _dataGrid.SelectedIndex;
    currentRow++;
    _dataGrid.SelectedIndex = currentRow;
    _dataGrid.Focus() ;
    _dataGrid.BeginEdit();
    }
}

我认为您需要更改CurrentItem属性。我使用不同的网格控制,所以我不能保证它会工作。但程序应该是这样的:

private void _dataGrid_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
       _dataGrid.EndEdit();
       int nextIndex = _dataGrid.SelectedIndex + 1;
       //should crash when enter hit after editing last row, so need to check it
       if(nextIndex < _dataGrid.items.Count)
       {
          _dataGrid.SelectedIndex = nextIndex;
          _dataGrid.CurrentItem = _dataGrid.Items[nextIndex];
        }
       _dataGrid.BeginEdit();
    }
}
private void\u dataGrid\u KeyUp(对象发送方,System.Windows.Input.KeyEventArgs e)
{
如果(e.Key==Key.Enter)
{
_dataGrid.EndEdit();
int nextIndex=\u dataGrid.SelectedIndex+1;
//在编辑最后一行后输入hit时应该崩溃,所以需要检查它
if(nextIndex<_dataGrid.items.Count)
{
_dataGrid.SelectedIndex=nextIndex;
_dataGrid.CurrentItem=_dataGrid.Items[nextIndex];
}
_dataGrid.BeginEdit();
}
}
遵循解决方案

private void _dataGrid_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
    if (e.Key == Key.Enter)
    {
        int rowCount = _dataGrid.Items.Count;
        int currentRow = _dataGrid.SelectedIndex;

        if (rowCount - 1 > currentRow)
            currentRow++;
        else
            currentRow = 0;

        _dataGrid.CurrentItem = _dataGrid.Items[currentRow];
        _dataGrid.BringItemIntoView(_dataGrid.Items[currentRow]);

    }
}

你好,雷纽兹,谢谢你的及时回复。我找到了解决办法。我设置了currentitem并使用了brinGitMinitoView方法。不需要begin和endedit方法。@rahul是的,我在某处看到该方法被使用:)因此,如果它现在工作正常-将代码作为答案发布,并接受它,其他用户知道将来的解决方案。祝你好运