Use of DBGridEh

Source: Internet
Author: User

DBGRIDEH is one of the components in the Enlib 3.0 package. The Enlib 3.0 package is a third-party component developed by Russians to enhance the functions of Borland development tools, it features user-friendly, powerful functions, high development efficiency, and quick preparation of preview/printing of simple Chinese reports. Therefore, the launch was favored by Borland programmers. Currently, this version supports Borland Delphi versions 4, 5, 6 & 7, and Borland C ++ Builder versions 4 & 5, which can greatly improve the performance of the database application system client. This component is used by many product software, such as "Fast reach 2000. The following is a summary of my experience using this component in the actual system development process.

The most important and powerful component in the Enlib3.0 package is the dbgrideh component. All the instances described in this article are debugged in the Delphi 7 development environment.

1. DBGridEh (enhanced table component)
The DBGridEh component is similar to the existing dbgrid component in Borland development tools in both appearance and function. It not only provides all the functions of the dbgrid component, but also adds the following new features:

● Select any data of multiple rows, columns, or rectangular areas.
● Set a common parent header row for multiple column headers.
● The Footer area at the bottom of the table displays the sum, count, and other statistical information.
● Auto adjust the width of the component to the width of the customer's region.
● Set the height of the header row and data row.
● Ultra-long title lines and data line text are automatically merged.
● The title line can be used as a button, and you can select whether to display the sort flag (Sort Descending △ascending ).
● Click the column title to automatically sort the current column without coding.
● You can automatically delete unnecessary parts that cannot be displayed in ultra-long text and use ellipsis (...) Replace.
● The Lookup data cell is displayed in the drop-down list of single and multi-column fields.
● You can perform incremental search for fields (Lookup) data cells.
● You can lock any number of columns without scrolling horizontally on the screen.
● The DateTime picker control supports the TDateField and TDateTimeField date formats.
● Display images in the associated ImageList Object Image Group based on different field values.
● Hide any column.
● Display 3D data areas, table tail areas, and locked rolling columns to create a 3D appearance table.
● Display Memo type field values.
● In addition to BOOLEAN data, other data types can also be displayed in the checkbox format.
● Use special functions and procedures to access the layout of tables saved in reg or INI File Format (including the data list, data column access sequence, column width, index ID, and row-level information) file.
● By setting the hint and ToolTips attributes of a data cell, when you move the cursor to the cell, the text content that the cell cannot accommodate can be displayed.
● Import/export data from components to files in various formats such as Text, Csv, HTML, RTF, XLS, and internal data.

The main attributes of the DBGridEh component are shown in the following table (for other attributes, see dbgrid ):

The DBGridEh component event is basically the same as that of DBGrid.

 

11:32:00
Comment & raquo;

11:33:10
 
 
11:33:33
 
 
11:37:47 II. Application Instance
After the Enlib3.0 package is successfully installed, the "enlib" Package label (1) is displayed on the system component panel. The method for adding DBGridEh to the form is the same as that for other components. After adding this component to the form, please join me to implement some special effects of Figure 2. For specific attribute settings, see the description of the Attribute Table.

A. Custom title line
1. Create a complex title line
A title row can be set to a height greater than two rows, and a common parent title row can be created for multiple columns. To achieve this effect, you need to separate the parent and sub-titles with "|" in each column title attribute. For example, office supplies include code and name. The specific attribute settings are as follows:

Usemultititile = true;
Titlelines = 2
DBGridEh. Columns [0]. Title. Caption: = 'Office supplies | Code ';
DBGridEh. Columns [1]. Title. Caption: = 'Office supplies | name ';

2. display the image in the header line
Display the title line of the buyer in Figure 2. First, add an imagelist component img1 and add a group of bmp and ico images. Set TitleImages of DBGridEh to img1. Finally, set the sequence number of the image in img1 to be displayed in the imageindex of the Column Title of the image to be displayed. Execute the program by pressing F9. Is it cool!

3. automatically display and sort the title line in ascending or descending order.
The DBGridEh component allows you to display the ascending and descending order of small triangle flags in the cells in the row of the title. You can click the row of the title during operation. The images are automatically switched and sorted accordingly. The specific attribute settings are as follows:

OptionsEh = dghAutoSortMarking
Column. Title. TitleButton = true

SortMarkedColumns is the current sorting column that can be used at runtime.
Then add the code in the ontitleclick event of the column:
Procedure TForm_Query.DBGridEh1TitleBtnClick (Sender: TObject; ACol: Integer; Column: TColumnEh );
Var
Sortstring: string; // sorting Column
Begin
// Sort
With Column do
Begin
If FieldName = ''then
Exit;
Case Title. SortMarker
SmNoneEh:
Begin
Title. SortMarker: = smDownEh;
Sortstring: = Column. FieldName + 'asc ';
End;
SmDownEh: sortstring: = Column. FieldName + 'asc ';
SmUpEh: sortstring: = Column. FieldName + 'desc ';
End;
// Sort
Try
Dataset. Sort: = sortstring // dataset indicates the actual dataset variable name.
Except
End;
End;
End;

Do not set the lookup field. Otherwise, an error is prompted.

In addition, I mentioned in the component manual that automatic sorting can be performed without coding, but I haven't found the Method for Automatic Sorting without coding. Please let me know if you know it! Let me also "lose weight" on the program code ".
(If you do not Program Automatic Sorting, you must add EhlibAdo, EhlibBDE, and EhlibCDS to USE after setting the attributes of automatic sorting, which of the following statements is determined based on the database type used, but only the query classes can be sorted. The table class does not work and an error is returned .)

 
11:38:16
 
 
11:39:41 B. Summary of the footer area at the bottom of the custom table
The DBGridEh component Displays summary rows at the bottom of the table, such as the total number of records, column field accumulation, and other information. In FooterRowCount, set the number of rows displayed at the bottom. Then, add one or more display columns in the Footers editor, the display column can be a collection type such as field value accumulation and total number of records, field value or static file. It can be set in the ValueType attribute during design, you can also set Footers [I] at runtime. valueType specifies its type. The meanings are shown in the following table:

Remember to set DBGridEh. SumList. Active to True to perform the summary statistics operation. Note that if the display type is not the accumulate sum of the current column, you need to specify the summary column in The fieldname attribute. If the type is other, this requirement is not required.

 
11:43:13
 
 
11:47:50 C. Custom table data unit appearance
1. display the corresponding small image based on different Field Values
For example, the corresponding picture is displayed in the data cell according to the status of the stock material. The specific settings are as follows:
Add an imagelist component img1 and add a group of bmp and ico images. Then, set the imagelist attribute of the column to be displayed as img1. Add the actual data storage value to the keylist attribute and set one row as a value. Remember to match the image sequence in imagelist, otherwise, Zhang guanli Dai will appear beyond the public view. You can also add the prompt information in the picklist, or set one row to a value and tooltip to true, when you move the mouse to the data cell during running, a prompt message is displayed while the image is displayed. How is the function powerful enough! You can use the space key or the mouse to switch the next image. The image switching also changes the actual storage data value. You can also switch to the previous image by shift + space or mouse. In this way, the image is switched from top to bottom.

2. display the checkbox appearance
The values of Boolean fields are automatically displayed as check boxes in the dbgrideh component. Generally, we need to display the non-Boolean field value. For example, if the gender field is gender type, the field value is "male", and the "female" field value is not selected. You need to set the actual stored data value in the keylist editor. The value of the first row is "1", the value of the second row is "0", and the other value is "2 ", three-state display is supported.

3. Show single and multi-column drop-down lists
Other table fields related to a cell field are displayed. For example, the Department Code field is displayed as the Department name. First, you must create a lookup field in the current table to set the fields and returned fields of the associated table. The multi-column drop-down list needs to be further set on the basis of a single column. Multiple Fields in the LookupDisplayFields are separated by the ";" sign, and the returned fields must be the first one. The specific settings are as follows:

Dropdownshowtitles = true
Dropdownsizing = true
Dropdownwidth =-1

For example, in the current table, only the Department Code has no department name column. You need to associate the table with the department. When you click a cell, the list is displayed in the drop-down list of the department code and department name columns.

4. display the calendar drop-down list
Values of the Date and DateTime types can be displayed in this form. The appearance is the same as that in the editing box. When you click the cell, the "calendar" symbol appears on the right. Click it to display the calendar drop-down list. If you do not want the calendar drop-down list to appear, you only need to set Column. ButtonStyle to cbsNone. This method is also applicable when other components are not displayed with special appearances.

5. 3D or flat exterior Effects
Set the appearance of fixed, frozen, footer, data rows, and other attribute tables in the OptionsEh attribute to 3D, and set flat to true to flat.

6. Lock multiple columns and do not scroll
This function is useful when the horizontal direction of a table cannot be displayed on a single screen. For example, the salary table contains information such as name, basic salary, and performance salary, which cannot be displayed on the screen. You need to move the horizontal scroll bar to display the next screen. If you do not lock the key field column, such as name, you do not know the name of the record when you move it to the next screen. Therefore, in practice, it is often necessary to lock multiple columns without scrolling.

For example, if the name field is the second column of the table, set FrozenCols = 2. in this way, when a screen cannot be displayed and the next screen is displayed by moving the horizontal scroll bar, the first two columns of the table are not scrolling as reference columns.

D. Import/Export data
Importing/exporting data is cumbersome in actual processing. However, Enlib3.0 provides a series of functions for you to easily implement this function, and supports many file formats: Text, Csv, HTML, RTF, XLS, and internal data formats. In addition, you can operate on any selected data area. The function is as follows:

Pascal: SaveDBGridEhToExportFile (TDBGridEhExportAsText, DBGridEh1, 'c: \ temp \ file1.txt ', False );

C ++: SaveDBGridEhToExportFile (_ classid (TDBGridEhExportAsText), DBGridEh1, "c: \ temp \ file1.txt", false );

Note: The "false" parameter indicates that the selected local data area data is exported, and the "true" parameter indicates that the entire table data is exported.

For example, export the data in the current table to an EXCEL file.
Add a SaveDialog component and the "Export" button B _exp to the form, and add the following code in the "Export" button's click event:

Procedure TForm1. B _ expClick (Sender: TObject );
Var
ExpClass: TDBGridEhExportClass;
Ext: String;
Begin
SaveDialog1.FileName: = 'file1 ';
If (ActiveControl is TDBGridEh) then
If SaveDialog1.Execute then
Begin
Case SaveDialog1.FilterIndex
1: begin ExpClass: = TDBGridEhExportAsText; Ext: = 'txt '; end;
2: begin ExpClass: = TDBGridEhExportAsCSV; Ext: = 'csv'; end;
3: begin ExpClass: = TDBGridEhExportAsHTML; Ext: = 'htm'; end;
4: begin ExpClass: = TDBGridEhExportAsRTF; Ext: = 'text'; end;
5: begin ExpClass: = TDBGridEhExportAsXLS; Ext: = 'xls '; end;
Else
ExpClass: = nil; Ext: = '';
End;
If ExpClass <> nil then
Begin
If UpperCase (Copy (SaveDialog1.FileName, Length (SaveDialog1.FileName)-2, 3) <> UpperCase (Ext) then
SaveDialog1.FileName: = SaveDialog1.FileName + '.' + Ext;
SaveDBGridEhToExportFile (ExpClass, DBGridEh1, SaveDialog1.FileName, False );
// Where false indicates local data
End;
End;
End;

E. convert an existing DBGrid component to a DBGridEh component.
Through the above introduction, I think you have already liked the Enlib package, and the more you want to try it out, download and use it now. However, after using it for a period of time and enjoying it, you have a new problem, that is, to keep the interface style consistent, can the DBGrid component in the developed application be converted to the DBGridEh component for a thorough revolution? The answer is yes. Although DBGridEh does not inherit from the CustomDBGrid component, there are many similarities between DBGridEh and DBGrid, so they can be converted to each other.

The procedure is as follows:
1. Open the TDBGrid component in Delphi IDE.
2. display form in text mode through the key combination Alt-F12;
3. Change the names of all TDBGrid objects to TDBGridEh objects, for example, DBGrid1: TDBGrid to DBGrid1: TDBGridEh;
4. Restore the text to form display again through the key combination Alt-F12;
5. Change all TDBGrid defined in various form-related events to TDBGrideh. For example, change DBGrid1: TDBGrid to DBGrid1: TDBGridEh;
6. recompile the application.

The above is just some of my experience using the dbgrideh component in the actual program development process, of course, its functions are far more than that. You are welcome to discuss with me further.

 

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/simeng1128/archive/2009/01/15/3791371.aspx

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.