How to determine if wpf datagrid cell is in edit mode?
There are two scenarios:
You select a row and press delete key to delete row.
You select a cell and when its text is highlighted 开发者_如何学Pythonyou press delete key to delete text.
How do I distinguish between the two? in both cases I catch PreviewKeyPress and the Key is Delete Key, selected row is same.
For identifying the source of keypress, capture e.OriginalSource
in the PreviewKeyPress(..)
and check whether a cast to DataGridRow
or DatagridCell
is successful.
DataGrid
has the IsReadOnly
property.
Check the selected DataGridCell
's IsEditing
property, perhaps? I assume that, if you've selected a whole row, there will either be no selected cell, or IsEditing will be false on the selected cells (since I don't believe you can edit cells when multiple are selected).
This approach may not work if, when you select a row, it automatically selects, say, the cell in the first column and puts it in editing mode... But I can't test that at the moment.
in OnPreviewKeyDown of the DataGrid:
if ((this.CurrentItem as DataRowView).IsEdit == false && ...)
{
// the row is in view mode
}
精彩评论