16th chapter-Application and programming of data browsing Parts (II.) (1)

Source: Internet
Author: User
Tags list of attributes first row

When displaying the record information in a database table in the Tdbgrid part, if Tdbgrid uses a dataset part that is dynamically generated during the run, Tdbgrid shows that the records in the database table display the record information in the table in the default order of the records in the table and in the default order of the fields. And you want to display the values of all the fields for each record in the table. And in most cases, to do this, users may want to display the fields of a record in the order in which they prefer them, and sometimes want to display only some of the field values of a record, and to do this, you must use the field editor at design time to create permanent field parts and set properties for each field part.

When you use the field editor (Fields Editor) to create a permanent field part for use with the Tdbgrid part, we can more flexibly display the record information in the database table in the Tdbgrid part. For example, in the Fields list box in the field editor, we can set the display order of the field parts, and after setting the display order of the fields, the Tdbgrid part displays the values of each field in that order. When we set the DisplayFormat and Editformat properties of the field part, the field value and the Edit field value are displayed in the Tdbgrid part in a set explicit and edit format; When the required property of a field part is set to true, When you insert a new record, you must enter the corresponding field value for the field, or you will get an error; By setting the Visible property of the field part, you can determine whether the corresponding field value is displayed in the Tdbgrid component. For more information about using the field editor to create a field part, see the 3.6.2 section for the properties of the field part.

Main properties and applications of 16.4.1 Tdbgrid components

The Tdbgrid part is an important part of displaying and editing record information in a database table, and is a powerful tool for displaying and editing record information in a database table that we use frequently during the design process. Tdbgrid has a number of important attributes that we can set up during the design phase of the program and when the program is running. Some important properties of Tdbgrid parts and their setting methods refer to the online Help file. Some of the important attributes in the Tdbgrid part are option attributes, DrawMode properties, and defaultdrawing attributes, and we focus on two attributes.

Options property: It is an extended property of the Tdbgrid part, and setting the Options property at the program design stage can control the display characteristics of the Tdbgrid part and the response characteristics to the event. When the Options property is displayed in the property bar of the Tdbgrid part, its front with a "+" logo, double-click the "+" flag, you can expand a boolean list of attributes, the user can modify each of the values of each of the properties, after modification can double-click the Options property before the "-" flag, Restores the Tdbgrid part's list of properties to its original display state.

Table 16.5 lists all the extended property entries that are contained in the options property and their impact on the Tdbgrid part.

Table 16.5 The Extended property entry in the Options property of the Tdbgrid part

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Attribute name values and effects

─────────────────────────────────

Dbediting True: By default this value ensures that the user can edit the interpolation in the grid

Entering and deleting records in a database table

False: You cannot edit, insert, and delete records in a table in a grid

─────────────────────────────────

Dbalwaysshow True: When a user selects a field in a record, automatically makes the field

Editor in Edit state

False: This value is by default. When a field is selected, it cannot

Automatically into edit state

─────────────────────────────────

Dgtitles True: This value is by default. Display field names in first row of grid

or field headings

False: Do not display field names or fields corresponding to the title in the grid

─────────────────────────────────

Dgindicator True: This value is by default. At the far left of the grid with a black arrow

The position where the current record pointer is located, and when the insert State, the arrow

The head becomes a star shape, and when edited, the arrow becomes the "I" head.

False: The position of the current record pointer is not identified in the grid

─────────────────────────────────

Dgcolumnresize True: This value is by default. The vertical divider by dragging the grid can

To change the width of each column in the grid, drag the

Column to display the vertical divider in the field header area.

False: The widths of columns in the grid cannot be changed

─────────────────────────────────

Dgclolines True: This value is by default. Display vertical between columns in a grid

Separator line.

False: Vertical dividers are not displayed in the grid

─────────────────────────────────

Dgrowlines True: This value is by default. Display the horizontal between rows in a grid

Separator line.

False: Horizontal separator lines are not displayed in the grid.

─────────────────────────────────

Dgtabs True: This value is by default. You can move between fields in a record

Enter focus (or select cue stick)

False: You cannot move the input focus between the name fields of a record, in a grid

When you press the TAB key, just jump out of the grid

─────────────────────────────────

Dgrowselect True: Select the cue stick to overwrite all fields in the entire record

False: This value is by default. Select cue sticks to overwrite only records at a time

One of the fields

─────────────────────────────────

Dgalwaysshow True: This value is by default. Always display a selection cue bar in the grid, i.e.

The same is true when-selection makes its control focus.

False: The selection cue stick is displayed only when the grid has the focus.

─────────────────────────────────

Dbconfirmdelete True: This value is by default. When you delete a record in a grid, the pop-up

Recognition information.

False: Do not eject the confirmation message when the record is deleted in the grid.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Users want to understand the effects and effects of these optional property items, and can also refer to the online Help information.

DragMode property: This property has two optional property values. When its value is set to Dmmanual, the user can drag and drop the columns in the grid while the application is running, changing the order and position of the columns in the grid. When you drag and drop a column in the grid and change its position in the grid, you just change the column's position in the dataset and do not change the location of its corresponding database table. When the value of this property is set to Dmautomatic, the user cannot use the mouse to drag and drop the columns in the grid to change its position in the grid.

Defalultdrawing Property: This property is a Boolean property that controls how each grid cell in the grid is plotted. By default, the value of this property is true, that is, Delphi uses the default method of the grid itself to draw the grid cells in the grid and to populate the contents of each grid cell. The data in each grid cell is displayed and plotted according to the DisplayFormat and Eidtformat properties of its corresponding field part. If the Defauldrawing property is set to False, Delphi does not automatically draw the data in each grid cell and grid cell in the grid. The user must write the appropriate program for the Ondrawdatacell event of the Tdbgrid part to draw the grid cells and the data in them.

After we understand the properties of the Tdbgrid part, we can use the Tdbgrid widget to display and edit the data in the database table. The property settings for each part of the application form shown in Figure 16.5 are shown in table 16.6.

Table 16.6 property settings for each part

━━━━━━━━━━━━━━━━━━━━

Property Name property value

────────────────────

Table1.databasename DEMOS

Table1.tablename customer.db

Table1.canmodify True

Datasource1.dataset Table1

Datasource1.autoedit True

Dbgrid1.datasource DataSource1

Dbgrid1.readonly False

━━━━━━━━━━━━━━━━━━━━

When editing the content in another data-browsing part (such as Tdbedit), when the user moves the focus to another part by using the TAB key or the mouse, the user's modifications to the field are automatically written back to the database table, and when the database table is modified using the Tdbgrid part edit, Delphi is recorded as the base unit will be modified to write back to the database table on the disk. When the user edits and modifies the current record in the table, only when the user moves the record pointer to another record does Delphi write the user's changes to the current record back to the database table on the disk, otherwise, Dephi will not post the user's changes to the current record, even if the user changes the focus to the other parts of the form. Delphi automatically checks the status of all data-browsing parts associated with the current database when posting the modified records in the Tdbgrid part to the database table, and whenever any of the data-browsing parts are modifying the data, an error message pops up and the current record changes are not posted ( is written back to the database table on disk).

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.