Set it up first.
Dbgrideh Property settings:
Indicatoroptions =
[Gioshowrowindicatoreh,//small triangular indication
Gioshowrecnoeh,//Data source line number
Gioshowrowselcheckboxeseh]//Show checkbox
Options = [..., dgmultiselect]//Turn on multiple selection to edit a checkbox
The above setup is complete, the function is there, for the selected row to traverse read
12345 |
for
I :=
0
to
DBGrideh
.
SelectedRows
.
Count -
1
do
begin
DBGrideh
.
DataSource
.
DataSet
.
Bookmark := DBGrideh
.
SelectedRows[I];
//定位
……
//读取定位后数据源其他操作
end
;
|
On the basis of the above to do a full select function upgrade.
The default Dbgrideh setting has the following settings
Allowedselections = [Gstrecordbookmarks,gstrectangle,gstcolumns,gstall]
At this point, the mouse click on the upper left corner of the Dbgrideh Indicatortitle can trigger the full selection of events, but unable to use the full selection of data records, find the next Dbgrideh.pas, found a key code
12345678910111213141516171819 |
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
;
|
The Dbgrideh is positioned by bookmarks the data source cursor row, where the default setting Allowedselections [Gstall,gstrecordbookmarks], when the Indicatortitle mouse click event is triggered, Found that the last piece of code run is to check Gstall first, and then check Gstrecordbookmarks, so although the selection, but unable to locate the data source cursor, so long as the allowedselections in the removal of [Gstall] can
No fields in the dataset are required.
However, this checkbox is easy to disappear, as long as the other rows of the grid can be clicked.
PassOptionsEh = [..., dghClearSelection, ...]
//dghClearSelection去掉
Method 2
There is a Boolean field in the DataSet, and a checkbox is automatically displayed.
Ehlib's Line checkbox