DBGridEh中使用checkbox进行数据选择
DBGridEh是Ehlib组件包中的组件之一,Ehlib组件包是一位俄国人为增强Borland系列开发工具功能而开发的第三方组件,它具有界面友好、功能强大、开发效率高、快速制作预览/打印简单中国式报表等特点。
DBGridEh控件件的属性设置
DBGridEh1.IndicatorOptions:=[gioShowRowIndicatorEh,gioShowRecNoEh,gioShowRowselCheckboxesEh];
options需要选上dgRowSelect及dgMultiSelect允许行选择及多选
DBGridEh1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgConfirmDelete,dgCancelOnExit,dgMultiSelect];
全选
DBGridEh1.Selection.SelectAll;
取消全选
DBGridEh1.Selection.Clear;
获取选中行数据
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
str: string;
begin
self.Memo1.Clear;
if UniQuery1.IsEmpty then
begin
ShowMessage('数据集没有数据');
exit;
end;
if (DBgridEh1.Selection.SelectionType <> gstAll)
and (DBgridEh1.SelectedRows.Count <= 0) then
begin
ShowMessage('请先选择数据');
exit;
end;
if DBgridEh1.Selection.SelectionType = gstAll then
begin
//全选
UniQuery1.First;
while not UniQuery1.Eof do
begin
Self.Memo1.Lines.Add(UniQuery1.FieldByName('id').AsString);
UniQuery1.Next;
end;
end
else
begin
//部分选择
for i := 0 to DBgridEh1.SelectedRows.Count - 1 do
begin
//方式一
//UniQuery1.Bookmark := DBgridEh1.SelectedRows.Items[i];
//方式二
UniQuery1.GotoBookmark(Pointer(DBgridEh1.SelectedRows.Items[i]));
Self.Memo1.Lines.Add(UniQuery1.FieldByName('id').AsString);
end;
end;
end;
测试验证效果