Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1065
Press Up or Down key to move edit mode to adjacent cell
posted

Hello,

When an XamDataGrid cell in edit mode, may I press the Up or Down key to move the edit mode to the adjacent cell? If so, are there any examples?

Thanks.

 

 

 

Parents
  • 69686
    Verified Answer
    posted

    Hello,

    Here is one way to achieve this by handling the PreviewKeyDown event of the XamDataGrid :

    void xamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e)

            {

                if (!xamDataGrid1.ActiveCell.IsInEditMode)

                {

                    return;

                }

                if (e.Key == Key.Left)

                {

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellLeft);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

                }

                if (e.Key == Key.Right)

                {

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellRight);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

                }

                if (e.Key == Key.Up)

                {

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellAbove);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

                }

                if (e.Key == Key.Down)

                {

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.EndEditModeAndAcceptChanges);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.CellBelow);

                    xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);

                }

            }

Reply Children