Tag: WPF/DataGrid/編集
| BeginEditCommand | F2 |
| CancelEditCommand | Esc |
| CommitEditCommand | Enter |
| DeleteCommand | Delete |
Deleteキーがおされた時にデフォルトのイベントハンドラが呼ばれる前に自前の処理を行う。
xaml
<DataGrid PreviewKeyDown="dataGrid_PreviewKeyDown">
</DataGrid>
コードビハインド
private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Delete)
{
var dataGrid = (DataGrid)sender;
MessageBox.Show("DELETEキーが押されました");
e.Handled = true; //trueを設定するとデフォルト動作は行われない。
}
}