Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to copy data from selected rows in a Data Grid to a clipboard. Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Copy selected rows in a DBGrid to a clipboard. 01-Mar-04
Category
Database-VCL
Language
Delphi 2.x
Views
673
User Rating
5
# Votes
3
Replies
0
Publisher:
Darley, F. Joe
Reference URL:
			1   
2   (* this code will help you copy data from selected rows in a Datagrid to a 
3   clipboard*)
4   
5   uses
6    Clipbrd;
7   
8   var
9      i, j: Integer;
10     sData: string;
11     SysClip : TClipBoard;
12  begin
13  
14  
15      SysClip := TClipBoard.Create;
16  
17      //used to create to copy the column Header
18       for i:=0 to DBGrid1.SelectedRows.Count do begin
19         sData:=sData+ uppercase(DBGrid1.Fields[i].DisplayName) ;
20        if i<>DBGrid1.SelectedRows.Count then
21            sData:=sData+ ', '+#09; //tab
22       end;
23        sData:=sData+#13#10; //carriage return
24  
25      if DBGrid1.SelectedRows.Count>0 then
26      with DBGrid1.DataSource.DataSet do
27        for i:=0 to DBGrid1.SelectedRows.Count-1 do
28        begin
29  
30         //goto the bookmark of the seleced row to copy its content
31          GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
32          for j := 0 to FieldCount-1 do
33          begin
34  
35            sData:=sData+Fields[j].AsString ;
36              if (j>0) then
37             sData:=sData+', '+#09;  //tab
38          end;
39          sData:=sData+#13#10;     //carriage return
40  
41        end;
42       SysClip.AsText := sData;  //copy data to clipboard
43       SysClip.Destroy;
44  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC