Expand the WPF DataGrid and press the arrow key to move the focus.

Source: Internet
Author: User
Tags wpf datagrid

Expand the WPF DataGrid and press the arrow key to move the focus.

The default moving behavior of the WPF DataGrid is as follows:

(1) When the current cell is not in the editing status, you can use the direction key to move the focus.

(2) When the current cell is in the editing status, you cannot use the direction keys to move the focus;
Press Enter to exit the editing status of the current cell. The focus moves down to a grid;
Press Ctrl + Enter to exit the editing status of the current cell, and move the focus to the upper limit;
Press the Tab key to exit the editing status of the current cell. The focus moves one cell to the right and enters the editing status;
Press Shift + Tab to exit the editing status of the current cell, move the focus to the left, and enter the editing status;

"Operation Management 3.0" users generally have low computer operation levels. Office is the most and most intelligent software they operate on. They believe that all software must be operated in the same way as Office, otherwise, negative reviews will be given, so they require "Operation Management" to be operated in the same way as Excel.

To implement the same way of moving the WPF DataGrid as Excel, You need to override the OnPreviewKeyDown event of the DataGrid:

 

Public class ExDataGrid: DataGrid {protected override void OnPreviewKeyDown (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 (); string mess = ex. message; if (ex. innerException! = Null) mess + = "nn" + ex. InnerException. Message; MessageBox. Show (mess) ;}} base. OnPreviewKeyDown (e );}}View Code

 


Replace the DataGrid with the overwritten ExDataGrid.

Reprinted from: http://www.yuzifu.net/index.php/2010/11/%E6%89%A9%E5%B1%95wpf%E7%9A%84datag


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.