日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

發(fā)布時(shí)間:2025/4/14 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先做設(shè)置

DBGrideh屬性設(shè)置:

IndicatorOptions =

[gioShowRowIndicatorEh, //小三角指示

gioShowRecNoEh,    //數(shù)據(jù)源行號(hào)

gioShowRowselCheckboxesEh]  //顯示CheckBox

?

Options = [……, dgMultiSelect]  //開(kāi)啟多選,才能對(duì)CheckBox進(jìn)行編輯

以上設(shè)置完成,功能就有了,對(duì)于選中的行進(jìn)行遍歷讀取

for I := 0 to DBGrideh.SelectedRows.Count - 1 dobeginDBGrideh.DataSource.DataSet.Bookmark := DBGrideh.SelectedRows[I]; //定位…… //讀取定位后數(shù)據(jù)源其他操作end;

?

補(bǔ)充全選及反選功能

DBGrideh.Selection.Rows.SelectAll; //全選,此時(shí)  SelectionType=gstRecordBookmarks
//下面會(huì)提到一個(gè)AllowedSelections,結(jié)合下文,這里不能用DBGrideh.Selection.SelectAll, 它的SelectionType=gstAll
DBGrideh.Selection.Clear; //全部取消

?

在以上基礎(chǔ)上做一個(gè)全選功能升級(jí)。?

默認(rèn)DBGrideh的設(shè)置中有如下設(shè)置

AllowedSelections = [gstRecordBookmarks,gstRectangle,gstColumns,gstAll]

此時(shí),鼠標(biāo)點(diǎn)擊DBGrideh左上角IndicatorTitle可以觸發(fā)全選事件,不過(guò)卻無(wú)法對(duì)全選的數(shù)據(jù)記錄進(jìn)行利用,查找了下DBGrideh.pas,發(fā)現(xiàn)了一段關(guān)鍵的代碼

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是通過(guò)Bookmarks定位數(shù)據(jù)源游標(biāo)行的,在此,默認(rèn)設(shè)置AllowedSelections中[gstAll,gstRecordBookmarks],當(dāng)觸發(fā)IndicatorTitle鼠標(biāo)點(diǎn)擊事件時(shí),發(fā)現(xiàn)上一段代碼運(yùn)行是先檢查gstAll,然后檢查gstRecordBookmarks,所以雖然全選了,但是無(wú)法定位數(shù)據(jù)源游標(biāo),所以只要在AllowedSelections中去掉[gstAll]即可

?

-----------------------------------

回復(fù)中有人提出通過(guò)此種方法,點(diǎn)擊DBGrideh任意地方,所選行容易消失

解決方法是設(shè)置DBGrideh中OptionsEh,使dghClearSelection=false

設(shè)置如下

OptionsEh = [..., dghClearSelection, ...]//,此內(nèi)dghClearSelection去掉

?

???

轉(zhuǎn)載于:https://www.cnblogs.com/jupt/p/4291902.html

總結(jié)

以上是生活随笔為你收集整理的在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。