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 transfer data between a TDBGrid and the 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
15-Oct-02
Category
Database-VCL
Language
Delphi All Versions
Views
193
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius 

How to transfer data between a TDBGrid and the clipboard

Answer:

The grid must be in Edit or Insert mode for the paste to work.

Add 'ClipBrd' to the Uses list
Add 'gk: Word;' to your global variables
Add the following procedures to Implementation, substituting names as required
1   
2   procedure TMyForm.MyDBGridKeyDown(Sender: TObject; var Key: Word; Shift: 
3   TShiftState);
4   {OnKeyDown event handler for your DBGrid}
5   const
6     vk_c = $43;
7     vk_v = $56;
8   begin
9     if Shift = [ssCtrl] then
10    begin
11      if key = vk_v then
12        Shift := [ssShift];
13      if (key = vk_c) or (key = vk_v) then
14      begin
15        gk := Key;
16        key := 0;
17      end;
18    end;
19  end;
20  
21  procedure TMyForm.MyDBGridKeyPress(Sender: TObject; var Key: Char);
22  {OnKeyPress event handler for your DBGrid}
23  const
24    vk_c = $43;
25    vk_v = $56;
26  begin
27    if gk <> 0 then
28    begin
29      Key := chr(0);
30      if gk = vk_c then
31        ClipBoard.AsText := MyTable.Fields[MyDBGrid.SelectedIndex].AsString;
32      if gk = vk_v then
33      begin
34        if (MyTable.State = dsEdit) or (MyTable.State = dsInsert) then
35          MyTable.Fields[MyDBGrid.SelectedIndex].AsString := ClipBoard.AsText
36        else
37          MessageBeep(0);
38      end;
39      gk := 0;
40    end;
41  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