怎样取出DBGrid的一个网格里选中的一部分数据,如何实现在DBGrid里较完美的复制剪切粘贴功能(100分)

  • 主题发起人 主题发起人 xhqing
  • 开始时间 开始时间
X

xhqing

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样取出DBGrid的一个网格里选中的一部分数据,如何实现在DBGrid里较完美的复制剪切粘贴功能,这样在网格里输入数据才方便.
我用以下程序,只能实现复制/粘贴整个网格里的数据,而不能只粘贴选取的部分数据,请高人指点,万分感谢!
procedure TmainForm.ToolButton_copyClick(Sender: TObject);
begin
Clipboard.Clear;
Clipboard.AsText :=DBGrid1.SelectedField.DisplayText;
showmessage(clipboard.AsText);
end;

procedure TmainForm.ToolButton_pasteClick(Sender: TObject);
begin
if (dbgrid1.ReadOnly = false)
then begin
adoquery1.Edit;
DBGrid1.SelectedField.AsString :=Clipboard.AsText;
try
adoquery1.Post;
except
adoquery1.Cancel;
end;
end;
end;

procedure TmainForm.ToolButton_cutClick(Sender: TObject);
begin
Clipboard.Clear;
Clipboard.AsText :=DBGrid1.SelectedField.DisplayText;
if (dbgrid1.ReadOnly = false)
then begin
adoquery1.Edit;
DBGrid1.SelectedField.Value := null;
adoquery1.Post;
end;
end;
 
用DBGRID难度较大, 找成DBGRIDEH就很容易, 代码如下可以参考一下:
procedure TReportBorwForm.gstAllExecute(Sender: TObject);
var
IsExportAll: Boolean;
begin
if (Sender as TAction).Tag = -1 then
Exit;
IsExportAll := Boolean((Sender as TAction).Tag);
if (not IsExportAll) and (DBGridEh1.Selection.SelectionType <> gstRectangle)
then
Exit;
SaveToExportFile(DBGridEh1, IsExportAll);

if (Sender <> ExecuteAction) and (PopupMenu1.PopupComponent <> DBGridEh1) then
begin
ExecuteAction.Hint := (Sender as TAction).Caption;
ExecuteAction.Tag := (Sender as TAction).Tag;
end;
end;
 
我是用DBGridEh1下面能正常显示你要的结果
ShowMessage(DBGridEh1.InplaceEditor.SelText);
你用dbgrid1对于InplaceEditor方法在TCustomGrid里。
 
谢谢您的指导,但是对于我用dbgrid1,在TCustomGrid里的InplaceEditor方法具体怎样调用呢?我的一个程序已接近尾声了,如要改用DBGridEh1,则要改许多许多地方,我真的不敢去想处处改的滋味.开始时做不到,我说算了,但现在总觉得编辑环境太不方便,还敬请您进一步指导!
 
另外,DBGridEh如何得到,用一段时间后要注册吗?
 
DBGridEh免费开源
 
我是这样实现的(因为停电至今才结贴):
type
Tmydbgrid = class(TDBGrid)
private
public
end;

procedure TmainForm.ToolButton_cutClick(Sender: TObject);
begin
if not( (dgAlwaysShowEditor) in (DBGrid1.Options))
then begin
DBGrid1.Options := DBGrid1.Options + [dgAlwaysShowEditor];
editOpen:=1;
end;

if (dbgrid1.ReadOnly = false) and (ActiveControl is TDBGrid)
then begin
Tmydbgrid(DBGrid1).InplaceEditor.CutToClipboard;
end;
ToolButton_paste.Enabled := true;

end;

procedure TmainForm.ToolButton_copyClick(Sender: TObject);
begin
if not( (dgAlwaysShowEditor) in (DBGrid1.Options))
then begin
DBGrid1.Options := DBGrid1.Options + [dgAlwaysShowEditor];
editOpen:=1;
end;

if (dbgrid1.ReadOnly = false) and (ActiveControl is TDBGrid)
then begin
Tmydbgrid(DBGrid1).InplaceEditor.CopyToClipboard;
end;
ToolButton_paste.Enabled := true;
end;

procedure TmainForm.ToolButton_pasteClick(Sender: TObject);
begin
if (dbgrid1.ReadOnly = false) and (ActiveControl is TDBGrid)
then begin
try
Tmydbgrid(DBGrid1).InplaceEditor.PasteFromClipboard;
except
end;
end;

{if (dgAlwaysShowEditor) in (DBGrid1.Options) then
DBGrid1.Options := DBGrid1.Options - [dgAlwaysShowEditor];}

end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
703
import
I
I
回复
0
查看
748
import
I
后退
顶部