1 2 (* this code will help you copy data from selected rows in a Datagrid to a 3 clipboard*)4 5 uses6 Clipbrd;
7 8 var9 i, j: Integer;
10 sData: string;
11 SysClip : TClipBoard;
12 begin13 14 15 SysClip := TClipBoard.Create;
16 17 //used to create to copy the column Header18 for i:=0 to DBGrid1.SelectedRows.Count dobegin19 sData:=sData+ uppercase(DBGrid1.Fields[i].DisplayName) ;
20 if i<>DBGrid1.SelectedRows.Count then21 sData:=sData+ ', '+#09; //tab22 end;
23 sData:=sData+#13#10; //carriage return24 25 if DBGrid1.SelectedRows.Count>0 then26 with DBGrid1.DataSource.DataSet do27 for i:=0 to DBGrid1.SelectedRows.Count-1 do28 begin29 30 //goto the bookmark of the seleced row to copy its content31 GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
32 for j := 0 to FieldCount-1 do33 begin34 35 sData:=sData+Fields[j].AsString ;
36 if (j>0) then37 sData:=sData+', '+#09; //tab38 end;
39 sData:=sData+#13#10; //carriage return40 41 end;
42 SysClip.AsText := sData; //copy data to clipboard43 SysClip.Destroy;
44 end;