EhLib的行Checkbox

摘要:
//读取定位结束后对数据源的其他操作;在此基础上,升级全选功能。默认DBGrid设置中包含以下设置:AllowedSelections=[gstRecordBookmarks,gstRectangle,gstColumns,gstAll]此时,单击DBGrid左上角的IndicatorTitle可以触发全选事件,但无法使用全选数据记录。搜索DBGrid后。pas,键代码12345678910111213141516171819procedureTCustomDBGridEh。找到DefaultIndicatorTitleMouseDown;varDropdown菜单:TPopupMenu;P: T点;ARect:TRect;begin……endelseif and DataLink.Active and then beginifSelection.SelectionTypegstNonthenSelection.ClearelseifgstallAllowedSelectionshenSelection.Select如果gstRecordBookmarksinAllowedSelection.Rows。全选;终止终止DBGrid通过书签定位数据源的光标行。这里,AllowedSelections中的默认设置为[gstAll,gstRecordBookmarks]。当触发“指示器标题”鼠标单击事件时,会发现上一次运行的代码首先检查gstAll,然后检查gstRecordBookmarks。虽然已选中所有字段,但无法找到数据源游标,因此只需从AllowedSelections中删除[gstAll]即可消除数据集中的字段。

方法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。

免责声明:文章转载自《EhLib的行Checkbox》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇iOS开发UI篇—Quartz2D简单使用(三)百度首页下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

input标签checkbox选中触发事件的方法

1.方法一 <input type="checkbox" onclick="checkboxOnclick(this)" /> <script> function checkboxOnclick(checkbox){ if ( checkbox.checked == true){ //Action for check...

jQuery获取Select选择的Text和Value(详细汇总)

语法解释:  1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text 3. var checkVa...

微信小程序checkbox样式修改

打开小程序开发者工具的调试模式,查看元素的样式,截图如下 完全看不到小程序是如何设置Checkbox的样式的,小程序实现Checkbox的样式代码对我们是黑盒的。 于是很多同学自己开始吭哧吭哧地编写一个模拟的组件,创建一个template,编写它的数据渲染和事件监听处理,以及对用户操作的数据进行实时更新,总之是自己要做一套类原生的工作。 本文要说的点就...