TStringGrid call copy/paste lazarus / 31-LCL ---------------------------------------------------------------------- sfeinst · 2010-03-09 14:45 The default processing of the TStringGrid works just the way I want regarding cut/copy/paste.  What i want to do is give the user a menu otpion to do the work.  How do I pass the key combination to the grid?  So if I create a menu, Copy which has a shortcut CTRL-C, what do I write in the body for the menu onclick to get the TStringGrid to operate as if CTRL-C were pressed on it? Thanks ---------------------------------------------------------------------- mathio · 2010-03-09 15:01 This is actually a copy. Is where you choose to save it? ---------------------------------------------------------------------- sfeinst · 2010-03-09 15:10 Quote from: mathio on March 09, 2010, 04:01:41 pmThis is actually a copy. Is where you choose to save it?  Sorry, I'm not sure what you are asking.  The CTRL-C on a TStringGrid will copy the selected cells.  I want to add a menu choice to the app that has a copy menu so the user can select the menu instead of pressing CTRL-C (I also want to add cut and paste as well). I'm trying to find out how to send the CTRL-C to the grid programmatically or to call a method on the grid which mimics what the CTRL-C does.  Grid.CopyToClipboard copies the whole grid (and I don't see a cut or paste). ---------------------------------------------------------------------- sfeinst · 2010-03-09 16:36 What I am doing right now is I subclassed TStringGrid.  Added 3 procedures which call DoCopyToClipboard, DoPasteFromClipboard and DoCutToClipboard.  This works, but I was hoping not to subclass the grid.  Too bad the Do..Clipboard methods are all protected. ---------------------------------------------------------------------- jesusr · 2010-03-09 18:15 In r23901 we added an optional parameter to CopyToClipboard if optional parameter is true, it will use grid.selection as range of cells if it's false the behavior is the same as before. ---------------------------------------------------------------------- jwdietrich · 2011-08-20 13:59 A possible solution for cut and copy is Code: [Select]procedure CutorCopyfromGrid(theGrid: TStringGrid; cut: Boolean = False); const   kTAB = #9;   kCRLF = #13#10; var   theSelection: TGridRect;   r, c: integer;   textfromSelection: AnsiString; begin   theSelection := theGrid.Selection;   textfromSelection := '';   for r := theSelection.Top to theSelection.Bottom do   begin     for c := theSelection.Left to theSelection.Right do     begin       textfromSelection := textfromSelection + theGrid.Cells[c,r];       if cut then       begin         theGrid.Cells[c,r] := '';       end;       if c < theSelection.Right then         textfromSelection := textfromSelection + kTAB;     end;     if r < theSelection.Bottom then       textfromSelection := textfromSelection + kCRLF;   end;   ClipBoard.AsText := textfromSelection; end;                        The original version of this is from http://borland.newsgroups.archive d.at/public.delphi.vcl.components.using.win32/200601/0601121293.html., but I simplified the code and adapted it to Lazarus.