The default move behavior for WPF's DataGrid is as follows:
(1) You can use the arrow keys to move focus when the current cell is not in the editing state.
(2) You cannot use the arrow keys to move the focus while the current cell is in the editing state;
Press ENTER, the current cell exits the edit state, and the focus moves down one cell;
Pressing the Ctrl+enter key, the current cell exits the edit state, and the focus moves up one grid;
Pressing the TAB key, the current cell exits the edit state, the focus moves one cell to the right, and enters the editing state;
Pressing the Shift+tab key, the current cell exits the edit state, the focus moves to the left one pane, and enters the editing state;
"Operations management 3.0″ users generally have low levels of computer operations, Office is the most and the most intelligent software they operate, they think all the software must be office-like operation, otherwise it will be poor, so they require" operations management "to operate as much as Excel.
In order for WPF to move the DataGrid in the same way as Excel, you need to rewrite the DataGrid's Onpreviewkeydown event:
Public classExdatagrid:datagrid {protected Override voidOnpreviewkeydown (KeyEventArgs e) {if(E.key = = Key.left | | e.key = Key.right | | e.key = KEY.UP | | e.key = =key.down) {Try { Base. Commitedit (); } Catch(Exception ex) {Base. CancelEdit (); stringMess =Ex. Message; if(ex. InnerException! =NULL) Mess+="nn"+Ex. Innerexception.message; MessageBox.Show (mess); } } Base. Onpreviewkeydown (e); } }View Code
Then replace the Exdatagrid with the rewritten ones where the DataGrid is used.
Reprinted from: Http://www.yuzifu.net/index.php/2010/11/%E6%89%A9%E5%B1%95wpf%E7%9A%84datag
Extend WPF's DataGrid to move focus by arrow key