EhLib使用说明(2)

EhLib使用说明
<script type="text/javascript"> <!-- google_ad_client = "pub-3171204447347529"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel ="0910615734"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_url = "008000"; google_color_text = "000000"; //--> </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>
一、如何在程序中确定Ehlib定义的报表表头颜色?

在执行打印之前,加上下面的语句:
DBGridEh1.FixedColor:=clLime;//clLime可以换成你想要的颜色比如clRed是红色等等
PrintDBgridEh1.Options:=[pghColored,pghFitingByColWidths];//方括号里的"pghColored"是必需的,其它的根据你的需要决定取舍
================================================================

二、Ehlib中的PrintDBGridEh如何印页码,即第几页共几页

PrintDBGridEh.PageFooter.CenterText:='第&[Page]页 共&[Pages]页'
在对象管理器中的相关位置有设
================================================================

三、本人刚学习使用ehlib包,现在要实现类似ehlib所带demo1中一个功能:点击dbgrid某列值
的下拉按纽(可以设置),弹出一个下拉列表(其内容是另一个dataset的)。我看demo1中
好象是使用了DBLookupComboboxEh,可我参看demo1怎么设置也不行,请指教。谢谢。

呵呵,这个效果没有用DBLoookupComboBoxEh,它是利用查找字段实现的。
它在Query1中,对应VName字段,增加了一个叫VName1的查找字段,这个
字段从qrVendors查找相关的数据,再在DBGridEh1显示VName1,这样显示
就是那种效果了。
===============================================================

四、Ehlib 怎样固定某几列?

只要设置dbGridEh的FrozenCols属性为几列即可.


EhLib 用户指南
内容


--------------------------------------------------------------------------------



3 使用 TDBGridEh 组件
理解 TDBGridEh, TDataLink 以及 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 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 mechanism 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 between, in that case DBGrid shows vertical 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和纵向滚动条
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.


定制网格标题
复杂标题
TDBGridEh 允许在多列上创建标题,例如:

设置 DBGridEh.UseMultiTitle 属性为 True 并且填充字段的标签或列标题的标题,可以使用下面的规则:字段标签中的文本部分或列标题必须由几部分组成,并且用 "|" 分割,几个列的每一个通用部分都设置为相同。其它字段或标题必须在相应的部分包含同样的文本。

例如:

Field1.DisplayLabel := 'Title1|SubTitle1';
Field2.DisplayLabel := 'Title1|SubTitle2';

DBGridEh.Columns[0].Title.Caption := 'Title1|SubTitle1';
DBGridEh.Columns[1].Title.Caption := 'Title1|SubTitle2';
按钮式标题
设置Column.Title.TitleButton 为 True可以强制标题单元为按钮式。写 OnTitleBtnClick事件来控制用户单击标题单元时的操作。

在标题中显示位图
To show bitmap in titles instead of caption use TitleImages property of TDBGridEh and ImageIndex property of TColumnTitleEh.

自动用位置标识排序标题.
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.

标题属性的默认值
使用TDBGridEh.ColumnDefValues.Title来设置标题属性的默认值。

定制网格页脚
页脚以及统计值
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.


定制网格数据单元
在数据单元中显示字段值为图形。
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.

检查框式的逻辑及非逻辑值
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.

数据行高度
使用 RowHeight 和 RowLines 属性来指定数据行高。完整的数据行高 = 行线高度+行高。设置 RowSizingAllowed 为 True 以允许可以在运行是使用鼠标来改变行高。

设置Column.WordWrap为True可以使数据行中文本多行显示。如果行高>文本行,它就换行。

显示备注字段
设置 DrawMemoText to True来显示文本式的备注字段。.

定制单元格字体及颜色
TDBGridEh 中的 Font 和 Color 属性描述了数据网格中绘制单元格的字体和颜色。
TColumnEh 中的 Font 和 Color 属性描述了指定列中绘制单元格的字体和颜色。

事件定制单元格字体及颜色
有几个事件可以让你能够在绘制单元格前定制单元格字体和颜色。你可以写TDBGridEh的OnDrawColumnCellEvent事件句柄来在控制在网格单元中绘制数据。你可以使用Canvas属性的方法来绘制单元格。但是如果你只想改变字体或颜色的属性,我建议你使用下面的事件。你可以写TDBGridEh的OnGetCellParams事件来控制在绘制数据单元以前所指定的操作。你可以改变绘制字体及背景色。这个事件适合你在想改变整行的字体或颜色时使用。如果你想改变指定列中单元格的属性,你可以使用TColumnEh.OnGetCellParams。写这个事件用来控制在一列数据单元被重绘或编辑时的操作。在一列数据单元被重绘以前,你可以改变绘制字体,背景色,对齐方式,图像索引,文本或检查框。在编辑一列数据单元以前,你可以改变编辑字体,背景色,文本或只读状态。

列属性的默认值

使用ColumnDefValues属性来设置列属性的默认值。新创建的列将从ColumnDefValues属性中获得属性值,并且直到第一次为其指定值为止。


在网格的适当位置放置编辑器.
在下拉列表中显示几个字段。
在下拉列表中显示几个下拉字段,需要设置列的LookupDisplayFields属性到字段的Semicolons属性来分割多个字段名。命名为Column.Field.LookupResultField的属性必须位于LookupDisplayFields列表中。多字段的下拉列表只能应用于下拉字段。

显示下拉方式的列

你可以通过KeyList 和 PickList 属性在相关的的字段中显示其它文本。KeyList显示包含在字段的值而非PickList索引所包含的值。 Column.NotInKeyListIndex to index of text from PickList that will be shown if field value do not contain in 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.

下拉式计算器
对于 TDateField 和 TDateTimeField 字段,inplace 编辑器将显示下拉按钮以显示显示下拉计算器。设置 Column.ButtonStyle 为 cbsNone 以禁止显示下拉按钮。

设置编辑器颜色和字体
Inplace编辑器可以设置数据单元的颜色和字体。数据单元使用OnGetCellParams 事件来控制列的颜色和字体。 Inplace 编辑器在行高>一行的高度时自动设置为多行模式并且将列的属性 WordWrap 设置为True.


自动填充网格列宽到网格客户区
设置AutoFitColWidths为True以自动重置列宽来设置网格的宽度等于客户区宽度。 MinAutoFitWidth 属性决定网格的最小宽度,列宽将会被重新计算。
3D或平面外观
使用 OptionsEh 属性来显示/隐藏固定的3D框架,冷区,页脚以及数据行。

使用 Flat 属性来设置用平面方式显示数据网格。

从多种格式导入/导出数据到TDBGridEh。
EhLib 的函数集可以从DBGridEh导出数据到Text, Csv, HTML, RTF, XLS以及其内部格式。它可以保存数据到流(TStream对象)或文件。

例子
Pascal: SaveDBGridEhToExportFile(TDBGridEhExportAsText,DBGridEh1,'c:/temp/file1.txt',False);
C++: SaveDBGridEhToExportFile(__classid(TDBGridEhExportAsText),DBGridEh1,"c://temp//file1.txt",false);

EhLib 的函数集可以从 Text以及其内部格式的数据导入到DBGridEh的数据集中。它可以从文件中读取数据或读取数据到流(TStream对象)。

其它特性
用lookup 编辑器,你可以在运行时清空(设置为Null) LookupKeyField 值。比如选择整个文本然后按Delete键。

冷区
冷区是数据网格列集左边显示的不可滚动的区域。与固定列不同的是,冷区的列可以获得编辑焦点。可以通过设置FrozenCols属性来设置右边不可滚动的列集。

增量搜索

TDBGridEh 允许用户在网格列中实现特定的“增量”搜索。当用户进入增量搜索时他可以显示字符以及网格,并且在当前的列中查找文本。使用 dghIncSearch 和 dghPreferIncSearch的值(在OptionsEh 选项中) 在数据网格中操作增量搜索。 dghIncSearch 值允许在数据网格中进行增量搜索。运行时你能够使用下面的键进行增量搜索:

Ctrl+F - 开始增量搜索。
Ctrl+Enter - 查找下一个匹配记录。
Ctrl+Shift+Enter - 查找前一个匹配记录。

如果OptionsEh选项中的 dghIncSearch 是只读的,那么网络将自动设置增量模式在第一次按键以及1.5秒后返回普通模式。 dghPreferIncSearch 值决定网格设置自动增量搜索模式在第一次按键时替代单元编辑。

水平或垂直滚动条
使用 VertSctollbar, HorzSctollbar 属性来显示/隐藏以及跟踪水平或垂直滚动条。

多选
TDBGridEh 允许在选定的区域上进行选择记录,列以及矩形区域等操作:

允许多选会影响下面这些属性:

Options选项中的dgMultiSelect属性 - 设置是否允许多选。

Options选项中的dghClearSelection 属性- 设置在用户移到下一个单元时是否清除已选记录。

Options选项中的EditActions属性 -设置用户可以在已选记录上执行哪些操作(比如,拷贝,剪切,删除,粘贴,全选等)。

Options选项中的AllowedSelections属性-设置允许选定记录的类型(比如,行,列,矩形区域等)。

Options选项中的Selection属性-设置一个当前的多选状态,已选记录,列或矩形区域以及存取它们的属性和函数。

从注册表或ini文件中保存或恢复网格和列的层次。
TDBGridEh 有一个常规设置来从注册表或ini文件中保存和恢复网络以及列的层次:

RestoreColumnsLayout - 从注册表中恢复列的次序,宽度,排序标志。

RestoreColumnsLayoutIni - 从ini文件中恢复列的次序,宽度,排序标志。

RestoreGridLayout - 从注册表中恢复列的次序,宽度,可视,排序标志,排序索引或行高。

RestoreGridLayoutIni - 从ini文件中恢复列的次序,宽度,可视,排序标志,排序索引或行高。

SaveColumnsLayout - 保存列的次序,宽度,排序标志到注册表中。

SaveColumnsLayoutIni - 保存列的次序,宽度,排序标志到ini文件中。

SaveGridLayout - 保存列的次序,宽度,可视,排序标志,排序索引或行高到注册表中。

SaveGridLayoutIni - 保存列的次序,宽度,可视,排序标志,排序索引或行高到ini文件中。

当前版本的TDBGridEh不支持的特性:
这个版本的TDBGridEh不支持下面的特性:

TDBGridEh 不能设置每一个数据窗口中单独行的行高。

TDBGridEh 不能象TreeView那样工作。它不能拥有节点和枝叶。

TDBGridEh 不能横向或纵向合并数据单元。

将已存在的TDBGrid组件转换为TDBGridEh组件:

尽管TDBGridEh并不是从TCustomDBGrid组件继承而来的,但是在TDBGridEh和TDBGrid中还是有一些相似的属性。

它允许仅用一点点代价来转换已存在的TDBGrid组件到TDBGridEh。

可以按照下面的提示来转转换已存在的TDBGrid组件到TDBGridEh:

在Delphi的IDE中打开包含有TDBGrid组件的应用程序。

设置视图方式为文本方式(Alt-F12)。

将所有的TDBGrid对象改名为TDBGridEh('比如,将object DBGrid1: TDBGrid'改为 'object DBGrid1: TDBGridEh')

重新编译你的应用程序。


--------------------------------------------------------------------------------

向前
向后
文档翻译:唐伟忠

内容

EhLib 用户指南
Contents


--------------------------------------------------------------------------------



5 使用 TDBSumList 组件
TDBSumList说明
你可以使用TDBSumList在可视动态变化数据集中进行记录统计。在你想查看的数据集中设置相关的数据字段,然后写 SumListChanged 事件来指定在TDBSumList发生改变后所要做的操作。TDBSumList 的 SumCollection 属性上一个 TDBSum 对象容器。每个 TDBSum 对象是一个可以指定集合值的元件。 FieldName 和 GroupOperation 决定了集合值的类型,SumValue 控制当前的集合值。

TDBSumList 被埋藏于 DBGridEh 组件中,因此所的下面有关TDBGridEh.SumList 的说明与TDBGirdEh的TDBGridEh.SumList 属性的说明是一样的。

如何工作以及为什么有时SumList的集合值计算不正确?
你知道 data-aware 控件与数据集是通过 TDataLink 对象相连接的。 TDataLink 不允许快速重新计算集合值。例如,当从数据集中删除记录时,数据集发送deDataSetChange事件给所有的TDataLink对象,在当前局部过滤发生改变时,同样的事件也被发送了。因此当 TDataLink 接收到该事件时,它不得不在所有的数据集中重新计算集合值,甚至于仅从数据集中删除一条记录。在激活后, TDBSumList 重载了数据集的下列事件: OnAfterEdit, OnAfterInsert, OnAfterOpen, OnAfterPost, OnAfterScroll, OnBeforeDelete, OnAfterClose。这种方法避免了在所有的数据集中它。在不需要它时,又会出现其它的问题,比如: T
运行时指定这些事件。在指定上述事件之一以前,关闭 SumList。
在下面的情形下,SumList 发出存取错误信息。 SumList 试着向数据集返回事件,但数据集数据并未被删除。在SumList(或网格)以及数据集放置在不同的窗体(数据模块)这种情况下,可以显示数据。在这种情况下,试着在从数据集或数据模块中数据集数据被删除时关闭SumList。
如果你使用SetRange或ApplyRange事件,SumList 将不能跟踪数据集中发生的变化。但可以调用 SumList.RecalAll 方法。
在非BDE数据集的主/明细表中,SumList 不能跟踪数据变化。在主数据集激活状态数据集发生变化后,调用 SumList.RecalAll 方法。
在任何其它情况下,如果你发现了其它SumList的计算值不正确,你都可以调用 RecalAll方法。


--------------------------------------------------------------------------------

向前
向后
翻译:唐伟忠

Contents

EhLib 用户指南
Contents


--------------------------------------------------------------------------------



5 使用 TDBSumList 组件
TDBSumList说明
你可以使用TDBSumList在可视动态变化数据集中进行记录统计。在你想查看的数据集中设置相关的数据字段,然后写 SumListChanged 事件来指定在TDBSumList发生改变后所要做的操作。TDBSumList 的 SumCollection 属性上一个 TDBSum 对象容器。每个 TDBSum 对象是一个可以指定集合值的元件。 FieldName 和 GroupOperation 决定了集合值的类型,SumValue 控制当前的集合值。

TDBSumList 被埋藏于 DBGridEh 组件中,因此所的下面有关TDBGridEh.SumList 的说明与TDBGirdEh的TDBGridEh.SumList 属性的说明是一样的。

如何工作以及为什么有时SumList的集合值计算不正确?
你知道 data-aware 控件与数据集是通过 TDataLink 对象相连接的。 TDataLink 不允许快速重新计算集合值。例如,当从数据集中删除记录时,数据集发送deDataSetChange事件给所有的TDataLink对象,在当前局部过滤发生改变时,同样的事件也被发送了。因此当 TDataLink 接收到该事件时,它不得不在所有的数据集中重新计算集合值,甚至于仅从数据集中删除一条记录。在激活后, TDBSumList 重载了数据集的下列事件: OnAfterEdit, OnAfterInsert, OnAfterOpen, OnAfterPost, OnAfterScroll, OnBeforeDelete, OnAfterClose。这种方法避免了在所有的数据集中它。在不需要它时,又会出现其它的问题,比如: T
运行时指定这些事件。在指定上述事件之一以前,关闭 SumList。
在下面的情形下,SumList 发出存取错误信息。 SumList 试着向数据集返回事件,但数据集数据并未被删除。在SumList(或网格)以及数据集放置在不同的窗体(数据模块)这种情况下,可以显示数据。在这种情况下,试着在从数据集或数据模块中数据集数据被删除时关闭SumList。
如果你使用SetRange或ApplyRange事件,SumList 将不能跟踪数据集中发生的变化。但可以调用 SumList.RecalAll 方法。
在非BDE数据集的主/明细表中,SumList 不能跟踪数据变化。在主数据集激活状态数据集发生变化后,调用 SumList.RecalAll 方法。
在任何其它情况下,如果你发现了其它SumList的计算值不正确,你都可以调用 RecalAll方法。


--------------------------------------------------------------------------------

向前
向后
翻译:唐伟忠

Contents

EhLib 用户指南

内容

4 使用 TPrintDBGridEh 组件
在 Delphi 的 IDE 组件面板中选择 TPrintDBGridEh 并拖放其到 form 上。在 其 DBGridEh 属性中设置为相应的 TDBGridEh 组件。使用 Print 以及 Preview 方法在打印机上打印网格或者在预览窗体中预览网格。
网格前以网格后的 RTF 文本
TPrintDBGridEh 允许在打印 / 打印预览网格前或网格后的 RTF 文本。使用 AfterGridText 以及 BeforeGridText 属性来指定文本。 你可以在打印 / 打印预览时通过 BeforeGridText 和 AfterGridText 属性来替换文本内容。
当前版本的 TPrintDBGridEh 不支持的特性。
这个版本不支持下面的特性:
TPrintDBGridEh 不能在一页中打印 / 打印预览多个网格。
问答列表 :
问 : 怎样进行横向打印 / 打印预览?
答 : TPrintDBGridEh 并没有专六的属性来设置页面特性。在调用打印或打印预览方法前,你必须设置你将要执行打印的打印源( Orientation )。
uses ......, PrViewEh, Printers.
..............
procedure TForm1.bPreviewClick(Sender: TObject);
begin
PrinterPreview.Orientation := poLandscape;
PrintDBGridEh1.Preview;
end ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值