locked
begin edit cell in datagrid without double click mouse to edit RRS feed

  • Question

  • my code in Grid_PreviewKeyDown event:

    var uie = e.OriginalSource as UIElement;
    
                if (e.Key == Key.Enter)
                {
                    e.Handled = true;
                    uie.MoveFocus(
                    new TraversalRequest(
                    FocusNavigationDirection.Next));
                }


    then the cell is selected but not move a cursor and open to edit .. without double click mouse on cell. why??
    Sunday, August 16, 2015 3:55 PM

Answers

  • You should call the BeginEdit() method of the DataGrid if you want to enter the edit mode programmatically:

    private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Enter)
                {
                    e.Handled = true;
                    uie.MoveFocus(
                    new TraversalRequest(
                    FocusNavigationDirection.Next));
    
                    yourDataGrid.BeginEdit();
                }
            }
    

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    • Proposed as answer by Xavier Xie-MSFT Monday, August 17, 2015 6:01 AM
    • Marked as answer by Techno-Live Thursday, August 20, 2015 10:30 AM
    Sunday, August 16, 2015 8:29 PM