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.
To copy & paste the
Gantt dependencies it must be set
CopyPasteInternal
or
since 13.3 there must be defined and copied column named "
id" that contains the row ids
or
since 13.3 there must be copied column
IdNames and
IdNames must contain only one column and
FullId must be
0.
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.
| 0 | Row cannot be copied and pasted. |
| 1 | Row can be copied and pasted. |
| 2 | Row can be copied and pasted only with its parent (when set CopyPasteTree). |
| 3 | Only 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 upd 13.3 <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.
| 0 | Does not copy tree. |
| 1 | Copies also visible children of expanded parents. |
| 2 | Copies also visible children of all parents. |
| 3 | Copies also all children. |
| 4 | (new 13.3) Does not copy any children, but preserves the tree structure, if copied selected parent with children. |
new 6.0 <Cfg> int
CopyPasteInternal
[0]
| 0 | Copies cell values to system clipboard and pastes from system clipboard. |
| 1 | Copies cell values to TreeGrid global private cache, it will be available for all grids on page. |
| 2 | Copies cell values to TreeGrid local private cache, it will be available only for this grid. |
new 6.3 upd 14.0 <Cfg> int
CopyPasteRows
[0]
| 0 | Copies cell values, but no other row or cell attributes. |
| 1 | Copies row ids only. It should be set with CopyPasteInternal>0 to copy the whole rows internally, with all attributes. Copies always all cells. |
| 2 | (new 14.0) Copies cell valuse and also row ids. If there are more grids on page, copies also grid id as the first cell. When pasting and the source row exists in the grid, makes a copy of this row. |
| 3 | (new 14.0) Like 2, but never copies the grid id. When pasting, it looks for the row only in the destination grid. |
| 4 | (new 14.0) Like 3, but never copies the row id. It stores the last copy and when pasting, it looks for the last copied row. |
new 13.3 <Cfg> int
CopyPasteHidden
[0]
new 14.0 <Cfg> int
CopyPasteDeleted
[0]
| 1.bit &1 | Copies and pastes also deleted columns. |
| 2.bit &2 | Copies and pastes also deleted rows. If permitted, the pasted new rows are not marked as deleted. |
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]
| 0 | Never copy selected rows. |
| 1 | Copy all selected rows/cells if any, otherwise copy focused row according to CopyFocused. |
new 6.0 upd 16.3 <Cfg> int
CopyFocused
[1]
It is applied only if
CopySelected is 0 or if no row in grid is selected.
| 0 | Never copy focused row. |
| 1 | Copy only focused rows. |
| 2 | Since 16.3 copy only focused rows and rows with CanCopyPaste=3 |
| 20 | Copy all visible variable rows in the same parent as focused row. |
| 30 | Copy all visible variable rows (if set CopyPasteTree, it affect only root rows, the other are handled by CopyPasteTree), copies also rows with CanCopyPaste=3. |
| 31 | Copy 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]
| 0 | Copies displayed text, usable for copying outside TreeGrid. |
| 1 | Copies value in editable format, usable when copying inside grid. |
new 13.3 <Cfg> int
CopyFormulas
[1]
| 0 | Copies only the cell value, never the EFormula. |
| 1 | If cell has the EFormula, it is copied internally to be pasted to TreeGrid. To clipboard there is always copied the cell value. |
| 2 | If cell has the EFormula, it is copied internally and also to clipboard with '=' prefix. If pasted outside TreeGrid, the formula cell references are not updated! |
new 6.0 upd 11.0 <Cfg> int
CopyCols
[1]
Which columns will be used for copy paste.
See also column attribute
CanCopyPaste.
| 0 | Only focused columns |
| 1 | All visible columns |
| 2 | All 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 upd 15.0 <Cfg> int
ExcludeClear
[0]
How the excluded cells will be cleared.
0 - rows will be deleted.
1 - cells will be cleared.
2 -
(new 15.0) cell values 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 canceled 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) or if set
ExcludeClear clears the copied cells.
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]
| 0 | Never paste to selected rows. |
| 1 | Paste 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 13.3 <Cfg> int
PasteFocused
[8]
It is applied only if
PasteSelected is 0 or if no row in grid is selected.
| 0 | Never paste to focused row. |
| 1 | To focused rows only, if the pasted range contains more rows, they are discarded. |
| 2 | To focused rows and to the next rows below, in the same parent only; if the pasted range contains more rows, they are discarded. |
| 3 | To focused rows and to the next rows below, including expanded children and parents; if the pasted range contains more rows, they are discarded. |
| 4 | To focused rows and new next rows are added after the focused rows. |
| 5 | Inserts 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. |
| 6 | Inserts new rows in front of the focused rows. The focused rows themselves are not changed. |
| 7 | Inserts 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. |
| 8 | Inserts 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).
Since 13.3 if the focused range contains last row in grid and pasted range contains more rows, they are added to the grid end.
|
|
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).
Since 13.3 if the focused range contains last row in grid and pasted range contains more rows, they are added to the grid end.
|
| 20 | Paste to all visible variable rows in the same parent as focused row. |
| 21 | Replace all siblings of focused row by the pasted rows. |
| 30 | Paste 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. |
| 31 | Paste 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. |
| 32 | Replace 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.
| 0 | Paste only to focused columns. |
| 1 | Paste to all visible columns. |
| 2 | Paste to all columns. |
| 3 | Paste to all columns right to the focused cell, including the focused one. |
| 4 | Paste 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]
| 0 | Ignore the pasted children. |
| 1 | Fill the children to the existing children only, use settings from CopyPasteTree. |
| 2 | Replace the children, if required, delete remaining children or add new children, use settings from CopyPasteTree. |
new 14.0 <Cfg> int
PasteErrors
[1]
If the
EditErrors messages will be displayed for pasting.
0 - never,
1 - only if pasted to cell range and not to the whole rows,
2 - always.
new 14.0 <Cfg> int
PasteNaN
[0]
If can be pasted value to cell that lead to NaN in cell, e.g. string to number cell.
0 - no, the cell will have original value.
1 - yes, the cell will get NaN value.
(default setting prior 14.0)
2 - empty, the cell will get empty or zero value.
new 16.6 <Cfg> bool
PasteNumbers
[0]
If set, TreeGrid tries to convert pasted formatted numbers to numbers instead of strings.
If the conversion is successful, the converted number is displayed unformatted, but can be better used in formulas.
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).
| 0 | The cell cannot accept pasted value. |
| 1 | The 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. |
| 2 | The 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 were 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".