0

私はCシャーププログラミングが初めてです。プロジェクトを変更する必要があります。基本的に、4 つの列を持つ Xeed データグリッドを使用しています。データはコレクション オブジェクトにバインドされ、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();
    }
}
4

2 に答える 2

0

CurrentItem プロパティを変更する必要があると思います。Iam は別のグリッド コントロールを使用しているため、それが機能することを保証するものではありません。ただし、手順は次のようにする必要があります。

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();
    }
}
于 2011-08-31T12:28:07.210 に答える
0

解決策に続いて

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]);

    }
}
于 2011-09-01T09:26:39.953 に答える