在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)
先做設置
DBGrideh屬性設置:
IndicatorOptions =
[gioShowRowIndicatorEh, //小三角指示
gioShowRecNoEh, //數據源行號
gioShowRowselCheckboxesEh] //顯示CheckBox
?
Options = [……, dgMultiSelect] //開啟多選,才能對CheckBox進行編輯
以上設置完成,功能就有了,對于選中的行進行遍歷讀取
for I := 0 to DBGrideh.SelectedRows.Count - 1 dobeginDBGrideh.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); varDropdownMenu: TPopupMenu;P: TPoint;ARect: TRect; begin ...... end else if (dgMultiSelect in Options) andDataLink.Active and ([gstRecordBookmarks, gstAll] * AllowedSelections <> []) thenbeginif Selection.SelectionType <> gstNon thenSelection.Clearelse if gstAll in AllowedSelections thenSelection.SelectAllelse if gstRecordBookmarks in AllowedSelections thenSelection.Rows.SelectAll;end; end;DBGrideh是通過Bookmarks定位數據源游標行的,在此,默認設置AllowedSelections中[gstAll,gstRecordBookmarks],當觸發IndicatorTitle鼠標點擊事件時,發現上一段代碼運行是先檢查gstAll,然后檢查gstRecordBookmarks,所以雖然全選了,但是無法定位數據源游標,所以只要在AllowedSelections中去掉[gstAll]即可
?
-----------------------------------
回復中有人提出通過此種方法,點擊DBGrideh任意地方,所選行容易消失
解決方法是設置DBGrideh中OptionsEh,使dghClearSelection=false
設置如下
OptionsEh = [..., dghClearSelection, ...]//,此內dghClearSelection去掉?
???
轉載于:https://www.cnblogs.com/jupt/p/4291902.html
總結
以上是生活随笔為你收集整理的在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vim 键盘指令高清图
- 下一篇: HTML5-canvas实例:刮刮乐游戏