日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/4/14 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在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学习(二)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。