How to understand CurrentCell is in edit mode or not in WPF DataGrid?

Viewed 123

I am creating custom DataGrid. When i press the keyboard i want to learn CurrentCell is in edit mode or not. I know how to handle KeyDown event. I found this and this post. The solutions there didn't help solve my problem. I couldn't find a better way to find out if CurrentCell is in edit mode or not. How can i achieve this? Is there any solution?

1 Answers

You could handle the BeginningEdit and CellEditEnding and use a variable to keep track of the currently edited cell:

private DataGridCellInfo _editedCell;

private void DataGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
    _editedCell = dataGrid.CurrentCell;
}

private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
    _editedCell = default(DataGridCellInfo);
}

You can then use the variable to check whether the cell is currently in edit mode:

if (dataGrid.CurrentCell == _editedCell)
...
Related