在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)
2015-02-14 15:45
423 查看
先做设置
DBGrideh属性设置:
IndicatorOptions =
[gioShowRowIndicatorEh, //小三角指示
gioShowRecNoEh, //数据源行号
gioShowRowselCheckboxesEh] //显示CheckBox
Options = [……, dgMultiSelect] //开启多选,才能对CheckBox进行编辑
以上设置完成,功能就有了,对于选中的行进行遍历读取
补充全选及反选功能
在以上基础上做一个全选功能升级。
默认DBGrideh的设置中有如下设置
AllowedSelections = [gstRecordBookmarks,gstRectangle,gstColumns,gstAll]
此时,鼠标点击DBGrideh左上角IndicatorTitle可以触发全选事件,不过却无法对全选的数据记录进行利用,查找了下DBGrideh.pas,发现了一段关键的代码
DBGrideh是通过Bookmarks定位数据源游标行的,在此,默认设置AllowedSelections中[gstAll,gstRecordBookmarks],当触发IndicatorTitle鼠标点击事件时,发现上一段代码运行是先检查gstAll,然后检查gstRecordBookmarks,所以虽然全选了,但是无法定位数据源游标,所以只要在AllowedSelections中去掉[gstAll]即可
-----------------------------------
回复中有人提出通过此种方法,点击DBGrideh任意地方,所选行容易消失
解决方法是设置DBGrideh中OptionsEh,使dghClearSelection=false
设置如下
DBGrideh属性设置:
IndicatorOptions =
[gioShowRowIndicatorEh, //小三角指示
gioShowRecNoEh, //数据源行号
gioShowRowselCheckboxesEh] //显示CheckBox
Options = [……, dgMultiSelect] //开启多选,才能对CheckBox进行编辑
以上设置完成,功能就有了,对于选中的行进行遍历读取
for I := 0 to DBGrideh.SelectedRows.Count - 1 do begin DBGrideh.DataSource.DataSet.Bookmark := DBGrideh.SelectedRows[I]; //定位 …… //读取定位后数据源其他操作 end;
补充全选及反选功能
DBGrideh.Selection.Rows.SelectAll; //全选,此时 SelectionType=gstRecordBookmarks //下面会提到一个AllowedSelections,结合下文,这里不能用DBGrideh.Selection.SelectAll, 它的SelectionType=gstAll DBGrideh.Selection.Clear; //全部取消
在以上基础上做一个全选功能升级。
默认DBGrideh的设置中有如下设置
AllowedSelections = [gstRecordBookmarks,gstRectangle,gstColumns,gstAll]
此时,鼠标点击DBGrideh左上角IndicatorTitle可以触发全选事件,不过却无法对全选的数据记录进行利用,查找了下DBGrideh.pas,发现了一段关键的代码
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]即可
-----------------------------------
回复中有人提出通过此种方法,点击DBGrideh任意地方,所选行容易消失
解决方法是设置DBGrideh中OptionsEh,使dghClearSelection=false
设置如下
OptionsEh = [..., dghClearSelection, ...]//,此内dghClearSelection去掉
相关文章推荐
- Android开发学习笔记:为动态添加的Spinner控件绑定数据源以及监听事件
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
- Spring实现动态数据源,支持动态添加、删除和设置权重及读写分离
- Jquery 实现动态添加table tr 和删除tr 以及checkbox的全选 和 获取添加TR删除TR后的数据
- Android开发学习笔记:为动态添加的EditText控件绑定值改变监听事件
- Spring实现动态数据源,支持动态添加、删除和设置权重及读写分离
- .NET漫游指南-004-在dataGrid中添加CheckBox支持单选,多选,全选功能
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性11
- c#动态添加CheckBox(全选及判断是否选中)
- Spring实现动态数据源,支持动态添加、删除和设置权重及读写分离
- Android高级控件(一)——ListView绑定CheckBox实现全选,添加和删除等功能
- easy-ui中表格中动态添加checkbox,和全选事件和判断选中事件
- jquery动态添加元素绑定事件学习记录
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
- jquery学习记录一:jquery动态添加html元素后设置其绑定事件
- jquery mobile Checkbox动态添加刷新及事件绑定
- 自己动手做一个支持动态绑定的多选CheckBoxList
- 【学习笔记三】- 动态添加元素绑定事件函数测试
- ASP.NET2.0下利用javascript实现TreeView中的checkbox全选 (支持IE/firefox)
- [★]ComboBox 经验总结[动态绑定数据之后,静态添加一条数据]