EhLib的行Checkbox

方法1

http://www.cnblogs.com/jupt/p/4291902.html

在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)

 

先做设置

DBGrideh属性设置:

IndicatorOptions =

[gioShowRowIndicatorEh, //小三角指示

gioShowRecNoEh,    //数据源行号

gioShowRowselCheckboxesEh]  //显示CheckBox

 

Options = [……, dgMultiSelect]  //开启多选,才能对CheckBox进行编辑

以上设置完成,功能就有了,对于选中的行进行遍历读取

1
2
3
4
5
for  I :=  0  to  DBGrideh . SelectedRows . Count -  1  do
begin
   DBGrideh . DataSource . DataSet . Bookmark := DBGrideh . SelectedRows[I];     //定位
  ……     //读取定位后数据源其他操作
end ;

 

在以上基础上做一个全选功能升级。 

默认DBGrideh的设置中有如下设置

AllowedSelections = [gstRecordBookmarks,gstRectangle,gstColumns,gstAll]

此时,鼠标点击DBGrideh左上角IndicatorTitle可以触发全选事件,不过却无法对全选的数据记录进行利用,查找了下DBGrideh.pas,发现了一段关键的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
procedure  TCustomDBGridEh . DefaultIndicatorTitleMouseDown(Cell: TGridCoord;
   Button: TMouseButton; Shift: TShiftState; X, Y:  Integer );
var
   DropdownMenu: TPopupMenu;
   P: TPoint;
   ARect: TRect;
begin 
     ......
end  else  if  (dgMultiSelect  in  Options)  and
     DataLink . Active  and  ([gstRecordBookmarks, gstAll] * AllowedSelections <> [])  then
   begin
     if  Selection . SelectionType <> gstNon  then
       Selection . Clear
     else  if  gstAll  in  AllowedSelections  then
       Selection . SelectAll
     else  if  gstRecordBookmarks  in  AllowedSelections  then
       Selection . Rows . SelectAll;
   end ;
end ;

DBGrideh是通过Bookmarks定位数据源游标行的,在此,默认设置AllowedSelections中[gstAll,gstRecordBookmarks],当触发IndicatorTitle鼠标点击事件时,发现上一段代码运行是先检查gstAll,然后检查gstRecordBookmarks,所以虽然全选了,但是无法定位数据源游标,所以只要在AllowedSelections中去掉[gstAll]即可

 

无需数据集中的字段。

但是,这个 checkbox 很容易消失,只要随便再点击 GRID的 其他 行 就全 没有了。

通过,OptionsEh = [..., dghClearSelection, ...]  //dghClearSelection去掉

 

方法2

数据集里 有 Boolean字段,自动会显示Checkbox。

转载于:https://www.cnblogs.com/CodeGear/p/4307196.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值