开发者

How to determine if wpf datagrid cell is in edit mode?

There are two scenarios:

  1. You select a row and press delete key to delete row.

  2. 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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜