Use of tdbgrideh

Source: Internet
Author: User
Tdbgrideh
It is introduced in the demo of some functions.
The following is a reference document!
3. Use the tdbgrideh component
Understand tdbgrideh, tdatalink, and tdataset.
All below text in equal degrees pertains as to tdbgrideh component as to TDBGrid component.
A tdbgrideh control lets you view and edit records in a dataset in a tabular Grid Format.
Tdbgrideh does not story data in itself, it only show data from dataset via tdatalink object. every Database Control have internal tdatalink object to interaction with dataset. you can connect tdbgrideh to dataset using datasource property. if you already use tstringgrid component you can see that data shows in tstringgrid and in tdbgrideh very similarly, but mechanic that use to show data in tstringgrid and in tdbgrideh very different. in tstringgrid count of rows is equal of rows in array of strings while in tdbgrideh (and TDBGrid) count of rows always not more then count of visible rows and although vertical scrollbar can display thumb position regarding the Count of record in dataset it take info not from grid but directly from dataset. tdataset don't allows us to work with data as with array of data I. e. we can not quickly get value of the field from certain record, some types of dataset have not even such notion as record number (in such datasets we can only know that we inhere in the begin of dataset or in the end of Its or somewhere, in that case DBGrid shows vertical scrollbar only in three positions ). but to have possibility to draw several record simultaneously tdatalink object allows to have buffer of records (Record Buffer window) with quick readonly access. DBGrid use this possibility of datalink and set size of record buffer window equal of Count of visible rows in grid. we can not control what record must be first in this buffer, datalink itself scroll record buffer window then we navigate through the dataset and it control the scrolling of record buffer window as that the active record as always in record buffer window. it is a reason why the active record change position when users change thumb position of vertical scrollbar using mouse.

Tdbgrideh and vertical scroll bar
If you works with different type of dataset you can notice that for some type of dataset DBGrid show vertical scrollbar validly but for over vertical scrollbar have only three position independently of record count in dataset. to set vertical scrollbar accomodation DBGrid use recordcount and recno property of dataset component. but some dataset and even same dataset under some condition holds-1 in recordcount and recno. dataset function issequenced indicates whether the underlying database table uses record numbers to indicate the order of records. when issequenced returns true, applications can safely use the recno property to navigate to records in the dataset and DBGrid use recno property to show thumb position in vertical scrollbar. but when issequenced returns false DBGrid can not define current record position and show vertical scrollbar in three positions. dbgrideh component have possibility to show proportional scrollbar for no sequenced dataset. to do it need to activate sumlist and create list of record bookmars. set sumlist. active to true and sumlist. virtualrecords to true. sumlist will run through dataset and create list of record bookmarks, if you use Client/Sever technology to access database sumlist will force dataset to fetch all records, so it operation can take much time. keep in mind that virtualrecords will work only for full relationship bookmarks dataset, it means that dataset. comaprebookmark function has to return> 0 if bookmark1> bookmark1 (I. e. record to which indicates bookmark1 have to be after record to which indicates bookmark1), = 0 if bookmark1 = bookmark1, <0 if bookmark1 = bookmark1. tbdedataset in most cases support full relationship bookmarks.

Custom grid title
Complex title
Tdbgrideh allows you to create titles on multiple columns, for example:

Set dbgrideh. when the usemultititle attribute is true and the label or title of the field is filled, you can use the following rule: The text part or column title in the field label must be composed of several parts, and separated by "|", each common part of several columns is set to the same. Other fields or titles must contain the same text in the corresponding section.

For example:

Field1.displaylabel: = 'title1 | subtitle1 ';
Field2.displaylabel: = 'title1 | subtitle2 ';
Or
Dbgrideh. Columns [0]. Title. Caption: = 'title1 | subtitle1 ';
Dbgrideh. Columns [1]. Title. Caption: = 'title1 | subtitle2 ';
Pressed title
If column. Title. titlebutton is set to true, the title unit can be forced to be In the pressing mode. Write the ontitlebtnclick event to control the operation when the user clicks the title unit.

Display bitmap in title
To show bitmap in titles instead of caption use titleimages property of tdbgrideh and imageindex property of tcolumntitleeh.

Automatically sort titles with location IDs.
Tdbgrideh allows to show special sortmarking bitmaps (small triangles) in the right part of title cell. in order to automatically marking title by sortmarking bitmaps add dghautosortmarking to optionseh property. add dghmultisortmarking too in order to allow sortmarking several columns simultaneously. set column. title. titlebutton to true for titles which will have possibility to change sortmarkers at run time. at runtime clicking on title will change sortmarking. holding ctrl key allows to Mark several columns simultaneously. after user change sormarking grid call onsortmarkingchanged event. you can write this event to change sorting and reopen in dataset. use sortmarkedcolumns property to access to sortmarked columns.

Default title Attribute Value
Use tdbgrideh. columndefvalues. Title to set the default value of the title attribute.

Custom grid footer
Footer and statistical value
Tdbgrideh allows to show special row (footer) or rows at bottom part. use footerrowcount property to specify the number of footer rows in the grid. use footer or footers property of tcolumneh object to specify information which need to show in footer cells. footers property useful then you have more then one footer rows. footers is a collection of tcolumnfootereh objects where information from I-th aliment of collection will be show in I-Th cell of footer column. in footer cell, it is possible to show: sum value for specified field, record count, value of a specified field or static text. use property footer. valuetype or footers [I]. valuetype to specify which type of value will be show in footer cell. if valuetype = fvtstatictext, then set the property value to specify text which need to show. if valuetype = fvtfieldvalue, then you need to set property fieldname to specify field, value of which need to show. to force grid to calculate total values need to activate sumlist (dbgrideh. sumlist. active: = true ). set valuetype to fvtsum and grid must to show sum value of the column field in the footer cell, you can also specify column. footer. fieldname to calculate total value of the other field. set valuetype to fvtcount to force grid to show count of records in the footer cell.

Custom grid data units
The field value is displayed as a graph in the data unit.
Tdbgrideh allows to show bitmaps from timagelist component depending on field values. to show bitmaps depending on field values need: Fill list of field values to column. keylist property (every value in separate line) and set column. imagelist property to imagelist control that has the bitmap in according index. set column. notinkeylistindex to index of Bitmap that will be shown if field's value does not correspond to any value in keylist (for instance you can set index of image for null field value ). at run time you are not allowed to edit bitmap in Column cell. use blank key and mouse click to set next value from column. keylist to the field; shift-blank key and shift-mouse click to set previous value from column. keylist. set column. dblclicknextval to true have allows to change value on mouse double click.

Check box logic and non-logical values
Grid automatically shows checkboxes for Boolean field. to show checkboxes for non Boolean fields fill first line of column. keylist property that corresponds to the checked state of the checkbox, second line-Non checked state, and set column. checkboxes ptoperty to true. line of keylist can represent more than one value in a semicolon-delimited list of items.

Data Row Height
Use the rowheight and rowlines attributes to specify the Row Height. The complete data Row Height = the row line height + the Row Height. Set rowsizingallowed to true to allow you to use the mouse to change the Row Height during running.

Setting column. wordwrap to true can display data rows in multiple Chinese lines. If the line is higher than the text line, it will wrap the line.

Show remarks field
Set drawmemotext to true to display text-style remarks ..

Customize cell fonts and colors
The font and color attributes in tdbgrideh describe the font and color of cells drawn in the data grid.
The font and color attributes in tcolumneh describe the font and color of cells drawn in the specified column.

Event customization cell font and color
There are several events that allow you to customize cell fonts and colors before creating cells. You can write the ondrawcolumncellevent event handle of tdbgrideh to draw data in the control grid unit. You can use the canvas attribute to draw cells. However, if you only want to change the font or color attributes, we recommend that you use the following events. You can write the ongetcellparams event of tdbgrideh to control the operations specified before the data unit is drawn. You can change the font and background color. This event is applicable when you want to change the font or color of the entire line. To change the attributes of cells in a specified column, you can use tcolumneh. ongetcellparams. Write this event to control the operations when a data unit is repainted or edited. Before a data unit is repainted, you can change the font, background color, alignment, image index, text, or check box. Before editing a column of data units, you can change the editing font, background color, text, or read-only status.

Default Value of column attribute

Use the columndefvalues attribute to set the default value of the column attribute. The newly created column obtains the attribute value from the columndefvalues attribute until it is specified for the first time.

Place the editor in the appropriate position of the grid.
Several fields are displayed in the drop-down list.
Several drop-down fields are displayed in the drop-down list. You need to set the lookupdisplayfields attribute of the column to the semicolons attribute of the field to separate multiple field names. The attribute named column. Field. lookupresultfield must be in the lookupdisplayfields list. The multi-field drop-down list can only be applied to drop-down fields.

Show drop-down columns

You can use the keylist and picklist attributes to display other texts in related fields. Keylist displays the values contained in the field instead of the values included in the picklist index. Column. notinkeylistindex to index of text from picklist that will be shown if field value do not contain keylist (for instance you can set index of text for null field value ). set column. dblclicknextval to true to change value on mouse double click.

Drop-down Calculator
For tdatefield and tdatetimefield fields, the inplace editor displays the drop-down button to display the drop-down calculator. Set column. buttonstyle to cbsnone to disable the drop-down button.

Set the editor color and font
The inplace editor can set the color and font of a data unit. The data unit uses the ongetcellparams event to control the color and font of the column. The inplace Editor automatically sets the Row Height to multi-row mode and sets the attribute wordwrap of the column to true.

Automatically fill in the grid column width to the grid customer area
Set autofitcolwidths to true to automatically reset the column width to set the grid width to the width of the customer zone. The minautofitwidth attribute determines the minimum width of the grid. The column width is recalculated.
3D or flat appearance
Use the optionseh attribute to display/hide fixed 3D frames, cold areas, footers, and data rows.

Use the flat attribute to display the data grid in a flat mode.

Import/export data from multiple formats to tdbgrideh.
The function set of ehlib can export data from dbgrideh to text, CSV, HTML, RTF, XLS and its internal format. It can save data to a stream (tstream object) or file.

Example
Pascal: savedbgridehtoexportfile (tdbgridehexportastext, dbgrideh1, 'c:/temp/file1.txt ', false );
C ++: savedbgridehtoexportfile (_ classid (tdbgridehexportastext), dbgrideh1, "C: // temp // file1.txt", false );

Ehlib function sets can be imported from text and data in its internal format to dbgrideh data sets. It can read data from a file or read data to a stream (tstream object ).

Other features
With the lookup editor, you can clear (set to null) The lookupkeyfield value at runtime. For example, select the entire text and press the delete key.

Cold Zone
The cold zone is the area that cannot be rolled on the left of the Data mesh set. Unlike Fixed columns, columns in the cold zone can obtain the editing focus. You can set the column set to the right by setting the frozencols attribute.

Incremental search

Tdbgrideh allows you to perform a specific "incremental" search in the grid column. When a user enters the incremental search, the user can display characters and grids, and search for text in the current column. Use the values of dghincsearch and dghpreferincsearch (in the optionseh option) to perform incremental search in the data grid. The dghincsearch value allows incremental search in the Data mesh. During running, you can use the following key for incremental search:

CTRL + F-start incremental search.
CTRL + enter-find the next matching record.
CTRL + Shift + enter-search for the previous matching record.

If dghincsearch in the optionseh option is read-only, the network automatically sets the incremental mode and returns the normal mode after the first key and 1.5 seconds. The value of dghpreferincsearch determines that the automatic incremental search mode of grid settings replaces unit editing when the first button is clicked.

Horizontal or vertical scroll bar
Use the vertsctollbar and horzsctollbar attributes to display/hide and track horizontal or vertical scroll bars.

Multiple choice
Tdbgrideh allows you to select records, columns, and rectangular areas in the selected area:

The following attributes are affected when multiple selections are allowed:

The dgmultiselect attribute in options-sets whether multiple options are allowed.

Dghclearselection property in options-sets whether to clear selected records when the user moves to the next unit.

Editactions attribute in options-set the operations that the user can perform on the selected records (for example, copy, cut, delete, paste, select all ).

Allowedselections attribute in options-set the type of the selected record (for example, row, column, and rectangular area ).

Selection attribute in options-set a current multiple-choice status, selected records, columns or rectangular areas, and access their attributes and functions.

Saves or restores the layers of grids and columns from the registry or INI file.
Tdbgrideh has a general setting to save and restore the network and column layers from the registry or INI file:

Restorecolumnslayout-restore the column order, width, and sorting flag from the registry.

Restorecolumnslayoutini-restore the column order, width, and sorting flag from the INI file.

Restoregridlayout-restore the column order, width, visibility, sorting flag, Sorting index, or row height from the registry.

Restoregridlayoutini-restore the column order, width, visible, sorting flag, Sorting index, or row height from the INI file.

Savecolumnslayout-Save the column order, width, and sorting flag to the Registry.

Savecolumnslayoutini-Saves the column order, width, and sorting flag to the INI file.

Savegridlayout-stores the column order, width, visualization, sorting flag, Sorting index or Row Height to the Registry.

Savegridlayoutini-Saves the order, width, and visibility of the column, sorting flag, Sorting index, or Row Height to the INI file.

The current version of tdbgrideh does not support the following features:
Tdbgrideh of this version does not support the following features:

Tdbgrideh cannot set the height of a single row in each data window.

Tdbgrideh cannot work like Treeview. It cannot have nodes and branches.

Tdbgrideh cannot merge data units horizontally or vertically.

Convert an existing TDBGrid component to a tdbgrideh component:

Although tdbgrideh is not inherited from the tcustomdbgrid component, tdbgrideh and TDBGrid still have some similar attributes.

It allows you to convert an existing TDBGrid component to tdbgrideh at only a small cost.

Follow the prompts below to convert an existing TDBGrid component to tdbgrideh:

Open the application containing the TDBGrid component in Delphi IDE.

Sets the view mode as text (Alt-F12 ).

Rename all TDBGrid objects to tdbgrideh (for example, change object dbgrid1: TDBGrid to 'object dbgrid1: tdbgrideh ')

Recompile your application

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.