Application of Data grid DBGrid in Delphi

Source: Internet
Author: User

Data grid is very popular data input and display form, like everyone familiar with the Excel97, VFP powerful brows, etc., for the vast number of programmers are happy to adopt. When using Delphi to develop database application system, when using data grid DBGrid input data, some fields only allow some fixed strings, such as the custody period of archives file, only "permanent", "Long" and "short" three kinds, can choose from a drop-down list, So as to facilitate input and avoid input errors? There are also some fields, such as the employee information base in the unit number (in addition to the other units in the library to save the details of the unit), in the input and display of employee data, can not operate the unit number, and the more intuitive unit in the library name? The answer is yes, Delphi. Data Grid Control DBGrid, supports the programming of Drop-down lists and lookup fields, and the programming process is visual and does not need to write a line of statements.

A drop-down list in the DBGrid

Implement the Drop-down list in the DBGrid grid, set the picklist string list of the field in DBGrid, and dropdownrows the initial ordinal value. Take the Origin field (string type) in the employee information base as an example, the specific design steps are as follows:

1, on the form to place Table1, DataSource1, DBGRID1, DBNavigator1 and other control objects, set the properties of each object according to the following table:

object properties set value
database sy1
zgk. DBF //Employee information base
datasou Rce1 table1
dbgrid1 datasource datasource1
datasource datasource1

2. Double-click Table1

In the pop-up Form1.table1 window, right-click the shortcut menu, click the AddFields menu item, and then press the OK button when all the fields are selected.

3, modify the 2nd step of the new field Displaylabel properties. Take the TABLE1ZGBH field as an example, select TABLE1ZGBH in the Objectinspector window

Modify the property displaylabel= the employee number, and the remaining fields are similar.

4. Double-click DBGrid1

In the pop-up Editing Dbgrid1.columns window, click the Addallfields button to increase all Table1 fields.

5, in the Editingdbgrid1.columns window, select JG this line, switch to the Objectinspector window, modify its picklist.strings for "Hubei Zhijiang, Beijing, Henan Pingdingshan, Zhejiang Deqing City"

6. Write the statement in the Form1.oncreate event:

Table1.open;

7, F9 run, with the mouse to click on a record of the origin of the field, right there is a button, click on this button, you can appear a Drop-down list, containing the 5th step entered the four line string, you can choose the mouse. Of course, you can also enter a string that is not subordinate to the Drop-down list.

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.