gpt4 book ai didi

delphi - 将 tdbgrid 的部分复制到剪贴板?

转载 作者:行者123 更新时间:2023-12-02 08:44:54 27 4
gpt4 key购买 nike

是否有任何方法可以轻松地将所选行从 Delphi 2007 中的 TDBGrid 复制到剪贴板?

最佳答案

此方法来 self 们的内部图书馆单元..

procedure BuildListFromDBGrid(DBGrid: TDBGrid; const FieldName: String; Strings :TStrings);
var
i: Integer;
begin
Strings.Clear();
with DBGrid do
begin
Strings.BeginUpdate(); // If assocated with a UI control (Listbox, etc), this will prevent any flickering
DataSource.DataSet.DisableControls();
try
for i := 0 to (SelectedRows.Count - 1) do
begin
Datasource.DataSet.GotoBookmark(Pointer(SelectedRows[i]));
Strings.Add(DataSource.DataSet.FieldByName(FieldName).AsString);
end;
finally
DataSource.DataSet.EnableControls();
Strings.EndUpdate();
end;
end;
end;

要将所选项目的列表添加到剪贴板,请将 Clipbrd 添加到您的 use 子句中并调用该过程。

var
SelectedItems :TStringList;
begin
SelectedItems := TStringList.Create();
try
BuildListFromDBGrid(MyDBGrid, 'InvoiceID', SelectedItems);
Clipboard.AsText := SelectedItems.Text;
finally
SelectedItems.Free();
end;
end;

当然,您可以修改上述方法或创建一个新方法,直接将所选项目添加到剪贴板(例如,多个字段,采用特殊格式等)

关于delphi - 将 tdbgrid 的部分复制到剪贴板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/397413/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com