Summary of applying the ehlib dbgrideh component to Delphi
[Dbgrideh (enhanced table component) function details]
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 writingCode.
● 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.
[Install ehlib in Delphi 7] (I spent half a day trying to fix it) the installation method in Delphi 7
1. copy the files in the common and dataservice folders in ehlib to the Delphi7 directory.
2. Add the ehlib path to tools> environment Options> library path.
3. Open ehlib70.dpk in the new folder and compile it, but do not install it.
4. Open ehlibdatadrivers70.dpk in the new folder and compile it, but do not install it.
5. Open dclehlib70.dpk in ehlib, compile and install
6. Open dclehlibdatadrivers70.dpk in ehlib, compile and install it (you can skip this step in practice)
7. An ehlib component page appears in the component panel.
8. Open the attached demos1, compile and run it, and test the installation.
[How to set the footer attribute of the dbgrideh control]
1. Set dbgrideh. footerrowcount: = 1
2. Set dbgrideh. sumlist. Active: = true;
3. Set columns [required and fields]. footer. valuetype: = vtsum;
In the end, note that in the formclosequery event, you must set the sumlist. active: = false, because after the data in the dataset is too large, formclose will let dbgrideh release all ehlib resources, which will make the exit very slow, so the sumlist. active: = false will not cause slow exit (not trial ).
[Implement dbgrideh color separation display]
Procedure tform1.dbgrideh1getcellparams (Sender: tobject; column: tcolumneh;
Afont: tfont; var Background: tcolor; State: tgriddrawstate );
Begin
If dbgrideh1.sumlist. recno mod 2 = 1 then
Background: = clinfobk
Else
Background: = RGB (238,238,238 );
End;
[Dbgrideh displays a specific color for a row under certain conditions]
Procedure tform1.dbgrideh1getcellparams (Sender: tobject; column: tcolumneh; afont: tfont; var Background: tcolor; State: tgriddrawstate );
Begin
// Set the row background color for the row whose name field value is AAA (when ADO is set)
If adoquery1.fieldbyname ('name'). asstring = 'aaa' then
Background: = $00ffc4c4
// Set the row background color when the XM field value is Li Ming (BDE setting)
Else if dbgrideh1.datasource. dataset. fieldbyname ('xm '). asstring = 'Li ming' then
Background: = $00ffc4c4
Else
Background: = $00 ffdddd;
End;
[Select all dbgrideh]
Procedure tform1.n _ copypollistclick (Sender: tobject );
Begin
If (activecontrol is tdbgrideh) then
With tdbgrideh (activecontrol) Do
If checkselectallaction and (geaselectalleh in editactions) then
Selection. selectall;
End;
[Output file of the ehlib dbgrideh control to excel] (in fact, the demo1 of ehlib already exists)
Procedure tform1.n _ saveselectionclick (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: = 'rtf ';
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, tdbgrideh (activecontrol ),
Savedialog1.filename, false );
End;
End;
End;
[Click the title in dbgrideh to sort by the field you clicked]
Procedure tform1.dbgrideh1titleclick (column: tcolumneh );
VaR
Sortstring: string; // sorting Column
Begin
// Sort
With column do
Begin
If fieldname = ''then
Exit;
If (title. sortmarker = smnoneeh) or (title. sortmarker = smdowneh) then
Begin
Sortstring: = column. fieldname + 'asc ';;
Title. sortmarker: = smupeh;
End
Else
Begin
Sortstring: = column. fieldname + 'desc ';
Title. sortmarker: = smdowneh;
End;
Try
Adoqrypolicylist. Sort: = sortstring; // dataset indicates the actual dataset variable name.
Except
MessageBox (handle, 'sorting error. Please verify and try again! ',' Hint ', mb_iconerror );
End;
End;
End;
Note: 1. Place a dbgrideh component on the form and connect it to the corresponding BDE dataset;
2. Set the dgautosortmarking attribute in [optionsen] of this component to true;
3. Double-click the component and add related fields in the pop-up property editor;
4. Set the titlebutton attribute of the [title] of the attribute list of the field to be sorted to true;
5. Do not forget to add the ehlibbde unit in the uses clause.
[Dbgrideh saves or restores the grid and column layers 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.
Example:
// Store the Grid Format ini
Function savegridini (adbgridehnamestr: string; adbgrideh: tdbgrideh): Boolean;
VaR
Inifilenamestr: string;
Begin
Inifilenamestr: = extractfiledir (paramstr (0) + '\' + 'dbgirdconfig. ini ';
Adbgrideh. savegridlayoutini (inifilenamestr, adbgridehnamestr, false );
End;
// load and read the Grid Format ini
function restoregridini (adbgridehnamestr: string; adbgrideh: tdbgrideh): Boolean;
var
inifilenamestr: string;
restoreparams: tdbgridehrestoreparams;
begin
inifilenamestr: = extractfiledir (paramstr (0 )) + '\' + 'dbgirdconfig. INI ';
adbgrideh. restoregridlayoutini (inifilenamestr, adbgridehnamestr, restoreparams);
end;