Copy and paste functions in DBGrid are transferred to Zhujiang Road Online

Source: Internet
Author: User

Copy and paste functions in DBGrid

Zookeeper provides the UT, copy, and paste acceleration buttons. For those who use the Windows Editor, I am afraid they are very familiar with and indispensable. Some controls in Delphi, such as tdbedit, tdbimage, tdbmemo, and tedit, have the cuttoclipboard, copytoclipboard, and pastefromclipboard methods. On these controls, you only need to use these methods through simple programming, the above acceleration button can be implemented. However, the TDBGrid control does not provide the above methods and cannot directly implement these functions. In standalone database applications, TDBGrid is often used to input data (including numbers and texts) without the copy and paste functions, which is inconvenient to use. In the programming process, I used the intermediate Control for "transition" to indirectly implement these functions.

Main Idea: Since the TDBGrid control cannot directly implement the copy and paste editing functions, you can set the field content in the TDBGrid control that needs to be edited, transfer to the control that has these functions (take tdbedit as an example). After editing, transfer it back to TDBGrid.

Specific Method: Add a tdbedit (set to dbedit1) control to the designed form containing the TDBGrid control (set to dbgrid1, the datasources attribute is set to the same as the datasources attribute of dbgrid1. The oncolenter event of the dbgrid1 control is programmed to make the datafield attribute value of dbedit1 equal to the field name of the selected field of the dbgrid1 control. Add two shortcut buttons in the form: copyand paste. you can select copy.bmp and paste.bmp in the imagesιbuttonssub-directory in the Delphi sub-directory. Program the onclick event of the copy quick button:
Dbedit1.copytoclipboard;

Program the onclick event of the paste quick button:
Dbedit1.pastefromclipboard;
Dbgrid1.selectedfield. asstring: = dbedit1.text;

In this case, if a cell number in dbgrid1 needs to be pasted with part or whole of cell2 in another cell, click and select cell2. In this case, dbedit1 displays the same content as cell2. In dbedit1, drag and drop the mouse to select part or all of the content, and click the copy quick button. Then, click the mouse to select the cell. In this case, dbedit1 displays the same content as the cell, in dbedit, insert the cursor at the position where the selected content is to be pasted and click the paste quick button. Then, the selected content is inserted to the cursor position, and the cell content is changed to the inserted content, this completes a copy-paste operation.

This method is used to perform the copy-paste operation. Compared with the normal operation, the copy-paste operation requires one mouse key and two mouse moves. This copy-paste method does not seem to be of much significance when there is not much repeated input and the operator's keyboard input is very skillful. However, if the application users are those who are not familiar with a certain kind of fast performance, please note that the umbrella, zinc, and so on. 5. The javasopy-paste method is not skilled (you cannot feel the exception of this method ), it is also a good method for turning over and searching in a long string of Homophone Words. If any reader can implement the conventional copy-paste operation in TDBGrid, please do not hesitate to inform us.

The program code is as follows:
Procedure tunitdetail. dbgrid1colenter (Sender: tobject );
Begin
Case dbgrid1.selectedindex
0: dbedit1.datafield: = unit? Num;
1: dbedit1.datafield: = unitname;
2: dbedit1.datafield: = header;
3: dbedit1.datafield: = address;
4: dbedit1.datafield: = Tel;
End;
End;

  
Procedure tunitdetail. sbcopyclick (Sender: tobject );
Begin
Dbedit1.copytoclipboard;
End;

Proceduretunitdetail. sbpasteclick (Sender: tobject );
Begin
Dbedit1.pastefromclipboard;
Dbgrid1.selectedfield. asstring: = dbedit1.text;
End;

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.