I want to be able to edit the last row when a button is pressed in a WPF Datagrid.

JunYoungLee 161 Reputation points
2022-06-18T03:02:11.267+00:00

Below is my code. I have implemented a code that moves the currentcell to the last row in the Datagrid and also scrolls it down when the current button is pressed.
But this code only moves the focus, and to edit the last cell, I have to double-click the mouse to enter edit mode.
Is there a way to enter the edit mode when the button is pressed and input a value into the cell without double-clicking the mouse?

private void btn_info_AddRow_Click(object sender, RoutedEventArgs e)  
        {              
            this.datagrid_eqp.Focus();  
            this.datagrid_eqp.SelectedIndex = this.datagrid_eqp.Items.Count - 1;  
            this.datagrid_eqp.ScrollIntoView(this.datagrid_eqp.Items[this.datagrid_eqp.Items.Count - 1]);  
            this.datagrid_eqp.CurrentCell = new DataGridCellInfo(datagrid_eqp.Items[this.datagrid_eqp.Items.Count - 1], datagrid_eqp.Columns[0]);  
        }  
Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JunYoungLee 161 Reputation points
    2022-06-18T03:19:46.437+00:00

    Sorry. I simply did this with this.datagrid_eqp.BeginEdit(); was added to the last line. I will leave the post without deleting it in case anyone else can find it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.