Copy & paste via clipboard

TreeGrid documentation

TreeGrid supports copying cells, rows, columns and cell ranges into and from clipboard.
The data are in the same format as standard in spreadsheet programs like MS Excel, so it is possible to copy & paste cells between TreeGrid and MS Excel.

The format of copied & pasted data
Rows are separated by CRLF. Last row is not followed by CRLF. In pasting it accepts also single CR and LF as row separators.
Cells are separated by tabulator. Last cell is not followed by tabulator.
If cell value contains one of characters CR (\r), LF (\n) (
), tabulator (\t) (	) and double quote (") ("), it encloses the value into double quotes and doubles all double quotes inside.
new 6.0 <C> bool

CanCopyPaste

[1]
If values can be copied from this column to clipboard by Ctrl+C and pasted to this column from clipboard by Ctrl+V.
If the column has CanCopyPaste = 0, it is ignored for both copying and pasting.
new 6.0 <I> int

CanCopyPaste

[1]
If values can be copied from this row to clipboard by Ctrl+C and pasted to this row from clipboard by Ctrl+V.
0Row cannot be copied and pasted.
1Row can be copied and pasted.
2Row can be copied and pasted only with its parent (when set CopyPasteTree).
3Only for fixed row, the row is always copied when all rows are selected and copied or all variable rows are copied. By default it is set for main Header.
new 6.0 <Cfg> int

CopyPasteTree

[0]
If and how there will be copied children of the rows.
If set to another value than 0, it adds level information to beginning of the first cell, as count of characters U65279.
0Does not copy tree.
1Copies also visible children of expanded parents.
2Copies also visible children of all parents.
3Copies also all children.
new 6.0 <Cfg> int

CopyPasteInternal

[0]
0Copies cell values to system clipboard and pastes from system clipboard.
1Copies cell values to TreeGrid global private cache, it will be available for all grids on page.
2Copies cell values to TreeGrid local private cache, it will be available only for this grid.
new 6.3 <Cfg> bool

CopyPasteRows

[0]
0Copies cell values, but no other row or cell attributes.
1Copies row ids only. It should be set with CopyPasteInternal>0 to copy the whole rows internally, with all attributes. Copies always all cells.
new 12.0 <Cfg> string[]

EditAttrs

[...]
The copy & paste is affected by EditAttrs, for more information see Mass cell changes.

Copying to clipboard

Copying to clipboard can be done only by pressing Ctrl + C or Ctrl + X.
There is no API method to copy to clipboard due browser security restriction.
new 6.0 <Cfg> bool

CopySelected

[1]
0Never copy selected rows.
1Copy all selected rows/cells if any, otherwise copy focused row according to CopyFocused.
new 6.0 <Cfg> int

CopyFocused

[1]
It is applied only if CopySelected is 0 or if no row in grid is selected.
0Never copy focused row.
1Copy only focused rows.
20Copy all visible variable rows in the same parent as focused row.
30Copy all visible variable rows (if set CopyPasteTree, it affect only root rows, the other are handled by CopyPasteTree), copies also rows with CanCopyPaste=3.
31Copy all variable rows (if set CopyPasteTree, it affect only root rows, the other are handled by CopyPasteTree), copies also rows with CanCopyPaste=3.
new 6.3 <Cfg> bool

CopyEdit

[1]
0Copies displayed text, usable for copying outside TreeGrid.
1Copies value in editable format, usable when copying inside grid.
new 6.0 upd 11.0 <Cfg> int

CopyCols

[1]
Which columns will be used for copy paste.
See also column attribute CanCopyPaste.
0Only focused columns
1All visible columns
2All columns
3(new 11.0) Only focused cell range or all visible columns for selected rows
4(new 11.0) Only focused cell range or all columns for selected rows
new 12.0 <Cfg> int

ExcludeClear

[0]
How the excluded cells will be cleared.
0 - rows will be deleted.
1 - cells will be cleared.
<cell> string

CopyValue

Cell value used for copying to clipboard by Ctr+C / Ctrl+X instead of actual cell value. Useful for HTML type columns.
new 9.3 <Cfg> int

CopyTime

[""]
Copying too many values to clipboard can be too slow and in this case the copying can fail, especially in IE and FF.
If the copying time exceeds this value (in milliseconds), the copying action is cancelled and the user must press the Ctrl+C again to finish the copying.
The CopyTime can contain up to four values used for different browsers in this order: [all, IE, FF, Safari/Chrome].
Reasonable value is "200,500,150,1000" or "150".
API event type

OnGetCopyValue

(TGrid grid, TRow row, string col, type val)
Called to get value for copying to clipboard by Ctrl+C.
val is predefined/actual cell value, return val or new value.
new 6.4 API event string

OnGetRowText

(TGrid grid, TRow row, string[ ] col, string txt, bool sel)
Called to get the whole row text, without ending CRLF.
cols are the cells to copy, txt is the default text to copy, sel is set if only selected cells are wanted.
Return new row text to copy to clipboard or txt.
The row text must not contain CRLF string.
new 6.0 <Actions>

Copy

Attached to event OnCtrlC, can be attached only to OnCtrlC or OnCtrlX
Copies data to clipboard.
Action in the CtrlC and CtrlX events must return 0 to permit the default function, use zero after comma like "Copy,0".
new 6.0 <Actions>

Exclude

Attached to event OnCtrlX, can be attached only to OnCtrlC or OnCtrlX
Copies data to clipboard and deletes the copied rows (only if all cells are copied).
Action in the CtrlC and CtrlX events must return 0 to permit the default function, use zero after comma like "Exclude,0".
new 6.0 API event bool

OnCopyStart

(TGrid grid)
Called before the data for copy is generated. Return true to suppress copying.
new 6.0 API event string

OnCopy

(TGrid grid, string txt)
Called after the data for copy is generated. txt is data to be copied to clipboard.
Return null to use the original txt, empty string to suppress copying or new text to copy.

Pasting from clipboard

Pasting from clipboard can be done only by pressing Ctrl + V.
There is no API method to paste from clipboard due browser security restriction.
chg 6.0 <Cfg> bool

Pasting

[1]
If pasting into grid is permitted
new 6.0 <Cfg> bool

PasteSelected

[1]
0Never paste to selected rows.
1Paste to selected rows/cells if any, otherwise paste to focused row according to PasteFocused.
If the pasted range is bigger, the remaining source rows/cells are discarded.
new 6.0 upd 12.0 <Cfg> int

PasteFocused

[8]
It is applied only if PasteSelected is 0 or if no row in grid is selected.
0Never paste to focused row.
1To focused rows only, if the pasted range contains more rows, they are discarded.
2To focused rows and to the next rows below, in the same parent only; if the pasted range contains more rows, they are discarded.
3To focused rows and to the next rows below, including expanded children and parents; if the pasted range contains more rows, they are discarded.
4To focused rows and new next rows are added after the focused rows.
5Inserts one new row in front of the focused rows; if the pasted range contains more rows, they are discarded. The focused row itself is not changed.
6Inserts new rows in front of the focused rows. The focused rows themselves are not changed.
7Inserts one new row in front of the focused rows; if the pasted range contains more rows, they are discarded. The focused row itself is not changed.
If clipboard contains only one value, it pastes it to the actual focused cell.
8Inserts new rows in front of the focused rows. The focused rows themselves are not changed.
If clipboard contains only one value, it pastes it to the actual focused cell.
9(new 11.0) To focused rows and to the next rows below, in the same parent only; if the pasted range contains more rows, they are added to end of the parent.
10(new 11.0) To focused rows and to the next rows below, including expanded children and parents; if the pasted range contains more rows, they are added to end of the grid.
11(new 12.0) If focused more cells, only to the focused rows, otherwise to focused rows and to the next rows below, in the same parent only; if the pasted range contains more rows, they are added to end of the parent. (= 1 or 9)
12(new 12.0) If focused more cells, only to the focused rows, otherwise to focused rows and to the next rows below, including expanded children and parents; if the pasted range contains more rows, they are added to end of the grid. (= 1 or 10)
20Paste to all visible variable rows in the same parent as focused row.
21Replace all siblings of focused row by the pasted rows.
30Paste to all visible variable rows (if set CopyPasteTree, it affect only root rows, the other are handled by CopyPasteTree), pastes also to rows with CanCopyPaste=3.
31Paste to all variable rows (if set CopyPasteTree, it affect only root rows, the other are handled by CopyPasteTree) , pastes also to rows with CanCopyPaste=3.
32Replace all variable rows with the pasted rows.
new 6.0 upd 12.0 <Cfg> int

PasteCols

[4]
Which columns will be used for paste.
See also column attribute CanCopyPaste.
0Paste only to focused columns.
1Paste to all visible columns.
2Paste to all columns.
3Paste to all columns right to the focused cell, including the focused one.
4Paste from actually focused column or, if the data are longer than the rest right to the cursor, pastes from the first column (= 2 or 1 or 3)
5(new 12.0) Paste to only focused columns (like 0), if there are more focused cells. Otherwise like 4.
new 6.0 <Cfg> int

PasteTree

[2]
0Ignore the pasted children.
1Fill the children to the existing children only, use settings from CopyPasteTree.
2Replace the children, if required, delete remaining children or add new children, use settings from CopyPasteTree.
new 6.0 chg 10.0 <cell> int

CanPaste

[1]
If and how can be pasted values written to the cell.
If pasted value cannot be written to the cell, it is discarded (it is not written to the next cell).
0The cell cannot accept pasted value.
1The cell accepts pasted value only if it is editable. To the pasted value are applied EditMask, ResultMask and Size.
Since 10.0 cannot be pasted not existing value to Enum type cell.
It permits pasting any value to not editable cell with Defaults Button or to Select type cell and to cell with SuggestType='Existing'. Use ResultMask to restrict pasting some value here.
2The cell always accepts the pasted value as is.
chg 6.0 API event bool

OnPaste

(TGrid grid, string[ ] cols, string[ ] pastedtext)
Called before cell values are pasted by Ctrl+V from clipboard.
Return true to suppress default action.
pastedtext is array of texts to paste into individual rows. You can modify this array.
cols is array of column names only where will be pasting done. You can modify this array.
chg 6.0 API event void

OnPasteFinish

(TGrid grid)
Called after cell values was pasted from clipboard.
new 6.4 API event bool

OnPasteRow

(TGrid grid, TRow row, string[ ] cols, string[ ] values, bool added)
Called before the values are pasted to the row cells (cols).
The cols array should not be modified - it is used also in next pasted rows.
added is set if the row was added by pasting.
Return true to cancel default behavior.
If true is returned and the row was added by pasting, it is not removed - must be removed by the handler!
new 6.4 API event void

OnPasteRowFinish

(TGrid grid, TRow row, string[ ] cols, string[ ] values, bool added)
Called after the values are pasted to the row cells (cols).
added is set if the row was added by pasting.
new 12.0 API event type

OnPasteValue

(TGrid grid, TRow row, string col, type value, type oldvalue, type[] attrvalues, string[] attrnames, object errors)
Called when pasting value to the cell. oldvalue is actual cell value.
Return new value to paste or value or oldvalue to not change the cell value.
It is possible to modify both the values in attrvalues and in attrnames.
For errors see OnEditErrors API event.
new 6.0 <Actions>

Paste

Attached to event OnCtrlV, can be attached only to OnCtrlV
Pastes data from clipboard.
Action in the CtrlV event must return 0 to permit the default function, use zero after comma like "Paste,0".