Preface: when using dview, you often need to modify its default operation mode. For example, press enter to go to the next column, or directly use enter as the tab key. This requirement is very simple for the datagridview. You need to rewrite the processcmdkey method. Another requirement is to perform special operations when the column to be edited is a specific datagridviewcolumn. In this process, we need to use the system message of the datagridview and the system message of the datagridviewcolumn to implement certain functions.
Convert the Enter key to the tab key.
This is quite in line with the Operation habits of ordinary users, because the datagridview is made by foreigners, and the popularization of common habits or operations in China is not enough. In this case, you only need to modify it yourself. You can use the processcmdkey method to operate the dview. The following is the implementation.
Protected override bool processcmdkey (ref message MSG, keys keydata)
{
Base. processcmdkey (ref MSG, keydata );
Int wm_keydown = 256;
Int wm_syskeydown = 260;
Bool _ disable = false;
If (msg. MSG = wm_keydown | msg. MSG = wm_syskeydown)
{
Switch (keydata)
{
Case keys. Enter:
Sendkeys. Send ("{tab }");
_ Disable = true;
Break;
}
}
Return _ disable;
}
Sendkeys. Send is the sending key message, which has the same effect as directly hitting the keyboard key. The above method means that when the sent system message is wm_keydown, wm_syskeydown, And the hit is the Enter key, the message is canceled and the tab Message key is sent.
Datagridviewcomboboxcolumn quick drop-down
If you have just started using datagirdview, you must feel that the ComboBox column is troublesome. If you have selected it, click here to start editing, and then click the following arrow to select the following actions.
For example
The user immediately pulls down the screen as soon as he presses the keyboard and then performs automatic filtering. This may be a good function (depending on the Operation habits of different people ).
This requirement can be achieved, while rewriting the processcmdkey method, capture the A-Z button, and determine whether the current is comboboxcolumn, but datagridviewcomboboxcolumn needs to be redefined, divide it into column, cell and editingcontrol files (for details, see the previous custom datagridview column article ).
When processcmdkey is rewritten, one captures the A-Z button, disabled it and sends the F2 key, F2 key is the insert operator, and needs to redefine the editingcontrol control, add onkeyup override, then judge the operation of the A-Z and send the F4 key, F4 is the drop-down Command key. In fact, you can also directly send F2 and F4 in processcmdkey. However, it may be troublesome to use processcmdkey during expiration.