×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Cut, Copy, and Paste in a DBGrid

Cut, Copy, and Paste in a DBGrid

Cut, Copy, and Paste in a DBGrid

(OP)
Does anyone know how to implement Cut, Copy, and Paste inside a DBGrid? <CTRL><X>,<CTRL><C>,and <CTRL><V> do not
work. If anyone can post a code sample demonstrating this I'd be greatful.
There is no built in call for this I can find so I assume it's a windows call thing.
Unfortunately I have no experience with that type of call.

RE: Cut, Copy, and Paste in a DBGrid

I haven't tried this but there is a TClipBoard component that allows you to cut and paste. Look at your help files. You should be able to call this component's members/methods and using them in your DBGrid. This is not a visible component so everything will have to be done in your DBGrid's code.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: Cut, Copy, and Paste in a DBGrid

(OP)
Yup, that helped. Thanks for the help.
I can now cut, copy, and paste the contents of a cell through the clipboard.
Unfortunately SelText is not a member of TField.
For some reason Fields don't have all of the properties
of an Edit box even though you need to do all the same
things with both.

Do you know how to get just the highlighted text from a cell?

RE: Cut, Copy, and Paste in a DBGrid

I couldn't find an easy answer. The only hint I saw was to make the cell a member of TClipBoard but I didn't find out how to do that.

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

RE: Cut, Copy, and Paste in a DBGrid

(OP)
If the editor doesn't chop this up beyond readability
this is the official answer to my problem.
It makes cut, copy, and paste work in all situations.
You have to turn off short cuts in the Menu's properties
to use this correctly. Posting it for the edification
of anyone else with a similar problem:

//---------------------------------------------------------------------------
// CUT COPY AND PASTE FUNCTIONS: WORKS WITH GRID!
//---------------------------------------------------------------------------
void __fastcall TMainForm::Cut1Click(TObject *Sender)
{
   if(((dynamic_cast<TDBGrid *>(ActiveControl))
     &&(dynamic_cast<TDBGrid *>(ActiveControl)->EditorMode))
     &&(dynamic_cast<TInplaceEdit*>(ActiveControl->Controls[0])->SelLength > 0))
         ActiveControl->Controls[0]->Perform(WM_CUT, 0, 0);

   else ActiveControl->Perform(WM_CUT, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Copy1Click(TObject *Sender)
{
   if(((dynamic_cast<TDBGrid *>(ActiveControl))
     &&(dynamic_cast<TDBGrid *>(ActiveControl)->EditorMode))
     &&(dynamic_cast<TInplaceEdit*>(ActiveControl->Controls[0])->SelLength > 0))
         ActiveControl->Controls[0]->Perform(WM_COPY, 0, 0);

   else ActiveControl->Perform(WM_COPY, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Paste1Click(TObject *Sender)
{
   if ((dynamic_cast<TDBGrid *>(ActiveControl))
       && (dynamic_cast<TDBGrid *>(ActiveControl)->EditorMode))
            ActiveControl->Controls[0]->Perform(WM_PASTE, 0, 0);

   else ActiveControl->Perform(WM_PASTE, 0, 0);
}
//---------------------------------------------------------------------------

RE: Cut, Copy, and Paste in a DBGrid

Cool!

James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close