Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut, Copy, and Paste in a DBGrid 1

Status
Not open for further replies.

Maladon

Programmer
Oct 5, 2001
25
0
0
US
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.
 
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.
 
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?
 
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.
 
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);
}
//---------------------------------------------------------------------------
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top