Use "OnEndDrag" to put selection of StringGrid on clipboard

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Use "OnEndDrag" to put selection of StringGrid on clipboard

Post by Dominic_Fichera » Sat Aug 08, 2015 6:44 am

Hey guys,

Pretty much like it says in the title, wanted to know if it was possible to use the event "OnEndDrag" or something similar to copy the selection of the StringGrid to clipboard? Alternatively, I'd be happy knowing I could copy using hotkeys too if that would work.

Thank you! :)

Dominic

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Use "OnEndDrag" to put selection of StringGrid on clipbo

Post by JRL » Mon Aug 10, 2015 1:49 pm

Took a script from HERE and modified it a bit. As-is if you double click a cell you can edit the cell. When the edited cell is "set" by either leaving the cell or by pressing enter, the contents of the StringGrid object are saved to a variable then the contents of that variable are placed in the clipboard.

Or, by adding an OnEvent>key_down to the script you can create a hotkey to control putting the stringgrid contents to the clipboard. The hotkey combination as posted below will be Ctrl + Shift + 1

I don't know how to make this work with OnEndDrag but I can look into it. What are you intending or hoping to drag? In past experiments with dialog drag/drop properties, I could only make drag and drop work with dialog objects. In other words I learned how to drag a button and drop it into a panel but I could not find a way to drag a desktop icon into a dialog and cause any functionality of any kind.

Hope this is helpful.

Code: Select all

OnEvent>key_down,1,6,GridToClipBoard

Dialog>Dialog1
object Dialog1: TForm
  Left = 649
  Top = 249
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 72
    Top = 152
    Width = 32
    Height = 13
    Caption = 'Cell Data'
  end
  object MSStringGrid1: tMSStringGrid
    Left = 16
    Top = 14
    Width = 320
    Height = 120
    ColCount = 3
    FixedCols = 0
    RowCount = 3
    FixedRows = 0
    Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
    TabOrder = 0
  end
end
EndDialog>Dialog1
/*
CSVDataLabel:
Shape,Colour,Size
Triangle,Red,Large
Square,Blue,Small
Oval,Yellow,Medium
*/
LabelToVar>CSVDataLabel,CSVData
SetDialogProperty>Dialog1,MSStringGrid1,LoadFromCSV,CSVData
AddDialogHandler>Dialog1,MSStringGrid1,OnSelectCell,doEdit
AddDialogHandler>Dialog1,MSStringGrid1,OnSetEditText,GridToClipBoard
Let>CellVal=
Let>comma=,
Show>Dialog1,r
SRT>doEdit
GetDialogProperty>Dialog1,MSStringGrid1,SaveToCSV,CSVSave
//PutClipBoard>CSVSave
Separate>CSVSave,crlf,vRow
Let>ChosenRow=%DoEdit_Arow%+1
Let>CsvRow=vRow_%ChosenRow%
Separate>CSVRow,comma,vCell
Let>ChosenCol=%DoEdit_Acol%+1
Let>CellVal=vCell_%ChosenCol%
SetDialogProperty>Dialog1,Label1,Caption,Row = %DoEdit_Arow%, Column = %DoEdit_Acol%, Value = %CellVal%
END>doEdit

SRT>GridToClipBoard
  GetDialogProperty>Dialog1,MSStringGrid1,SaveToCSV,CSVSave
  PutClipBoard>CSVSave
END>GridToClipBoard

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts