Row adding and copying
TreeGrid documentation
Only variable rows can be added or copied.
Fixed (Head and Foot) and Space rows
cannot be added or copied.
Ways of adding rows to grid
Adding new empty row
New empty row can be added by actions
AddRow,
AddChild and other
Add... actions. These actions are usually attached to Toolbar
Add and
AddChild Button and also to
CopyMenu menu.
By API can be new row added by
AddRow method.
All the settings are described below in Adding new empty rows paragraph.
Copying existing row
Existing row can be copied by actions
CopyRow,
CopyTree,
CopySelected and other
Copy...action. These actions are usually accessible from
CopyMenu menu.
It is possible to copy row only, copy row with children, copy row with children, but without values, copy selected rows - with or without children.
By API can be existing rows copies by
CopyRows method.
All the settings are described below in Copying existing rows paragraph.
Copying existing row by dragging
Existing rows can be copied when dragging by actions
DragCopy,
DragSelectedCopy,
DragCopyChildren. These actions are not attached to any event by default, because by default are rows moved by dragging.
The copying actions can be attached to
OnDrag... events and replace DragRow, DragSelected and DragChildren events that move the rows.
All the settings are described in Row moving documentation.
Moving existing row from another grid by dragging
From another grid are rows move always as copy - from source grid are deleted (marked as Deleted) and added as new to the destination grid.
The dragging rows can be done by actions
DragRow,
DragSelected and
DragChildren events. These actions are usually attached as default actions for dragging rows to
OnDrag event.
By API can be rows moved from another grid by
MoveRowsToGrid method.
All the settings are described in Row moving documentation.
Pasting row from clipboard
TreeGrid supports pasting new rows from clipboard. To clipboard can be rows copied from the grid, from another grid, or from another application like MS Excel.
The pasting is done by actions
PasteTo... These actions are attached to CtrlV event and cannot be attached alsewhere.
All the settings are described in Copy&Paste documentation.
Adding and copying restrictions
By default every row accepts every child. Remember, only variable rows can be added or copied!
To control which row accepts which child use
Def and
AcceptDef attributes. The row accepts as child only rows with
Def attribute listed in the row's
AcceptDef array. The root rows are controlled by <Root
AcceptDef/>.
The new empty row gets its
Def attribute from
CDef attribute of its parent. Root rows use <Root
CDef/>. To restrict adding to row's children, set its
CDef="". By default is
CDef="R".
Dynamically you can control adding new rows by API event
OnCanRowAdd.
All the settings are described in Default rows documentation.
Adding new empty rows
<Cfg> bool
Adding
[1]
If rows can be added into grid.
If set to 0, grid does
not permit adding new rows, copying existing rows and pasting rows from clipboard, but it is still permitted moving rows from another grid.
If set to 0, it hides Toolbar buttons Add and AddChild. If set to 0 all
Add... actions fail, but
AddRow method still works.
new 6.4 <Cfg> string
AddFocusCol
When set, automatically focuses this column after the row is added.
If not set, the originally focused column is used.
new 14.0 <Cfg> string
AddFocusColEmpty
When set, automatically focuses this column after the row is added if no column is focused originally.
<I> bool
Added
[0] Uploaded to server, support Undo
It is set to
1 when row has been added to the grid and not yet uploaded to server.
It is set to 1 for every type of adding the row (add empty, copy, drag copy, move from other grid, paste).
Added row is colored green (by default setting in Grid.css).
After uploading changes to server or calling
AcceptChanges the added row just looses its state and becomes normal row.
The place where the row is added is identified by
Parent,
Next and
Prev attributes.
<I> string
Parent
Uploaded to server
When the row is moved or added, this is id of the new parent row or position of page (from 0).
<I> string
Next
Uploaded to server
When the row is moved or added, this is id of the row below or "" if the row is the last row in its parent.
<I> string
Prev
Uploaded to server
When the row is moved or added, this is id of the row above or "" if the row is the first row in its parent.
<I> <Root> int
AddParent
[0]
If set, adds new row's children as its siblings rather than its children.
If is set to
1 adds new row before the row.
If is set to
2 adds new row as last child of the parent row.
For example, if you set AddParent of all rows and <Root> to
2, every new row will be added to the end of table, to the root.
<Actions>
AddRow ...FA
Attached to OnClickButtonAdd and OnIns and used in Toolbar Add and Panel Menu
Adds new empty row above actual or focused row.
<Actions>
AddRowBelow ...FA
Not attached to any event
Adds new empty row below actual or focused row.
upd 14.0 <Actions>
AddRowEnd
Attached to OnClickButtonAdd event and used in Toolbar Menu
Adds new empty row to the end of grid (when
<Cfg AllPages='1'/>) or actual page (when
<Cfg AllPages='0'/>).
There are also available actions
AddRowEndGrid to add row to the grid end and
AddRowEndPage to add row to actual page end.
It always creates brand new row and ignores
EditAttrsEmpty attribute.
Since 14.0 it can be used with F suffix to add row to end of focused nested grid if any.
<Actions>
AddChild ...FA
Not attached to any event
Adds new empty row into actual or focused row's children to the beginning (as the first child).
<Actions>
AddChildEnd ...FA
Attached to OnClickButtonAddChild and OnCtrlIns and used in Toolbar AddChild and Panel Menu
Adds new empty row into actual or focused row's children to the end (as the last child).
new 12.0 <Actions>
Not attached to any event, used in Toolbar Add Menu
Adds new empty rows above actual row or focused range.
It adds the same number of rows as the focused range contains.
The suffixes
FA control destination (the position to add), the suffixes
SRWO control source (the count).
new 12.0 <Actions>
AddRowsBelow ...FSARWO
Not attached to any event
Adds new empty rows below actual row or focused range.
It adds the same number of rows as the focused range contains.
The suffixes
FA control destination (the position to add), the suffixes
SRWO control source (the count).
new 12.0 <Actions>
AddSelected ...FSARWO
Not attached to any event
Adds new empty rows above actual or focused row.
It adds the same number of rows as the selected rows.
The suffixes
FA control destination (the position to add), the suffixes
SRWO control source (the count).
new 12.0 <Actions>
AddSelectedBelow ...FSARWO
Not attached to any event
Adds new empty rows below actual or focused row.
It adds the same number of rows as the selected rows.
The suffixes
FA control destination (the position to add), the suffixes
SRWO control source (the count).
chg 12.0 upd 16.1 API event bool
OnCanRowAdd
(TGrid grid, TRow parent, TRow next)
Called before the row is added to find out if it can be added to this position.
It is called when adding new rows, copying existing rows and pasting rows. It is
not called when moving rows from another grid.
parent is parent row in tree or page for root row, to its children the new row will be added.
next is next row, above it the new row will be added or null if the row will be added as the last child or last row on page.
Return false to restrict row adding.
Since 12.0 returning null permits row adding.
Since 16.1 is possible to return array as [parent,next] to change to place where the row can be added.
API event void
OnRowAdd
(TGrid grid, TRow row)
Called after the row is added, but before it is displayed. Usually to change default values. Called from
AddRow.
new 7.0 upd 14.0 API event void
OnRowAdded
(TGrid grid, TRow row, bool paste)
Called after the row is added and displayed.
Called also when the row is copied, but not moved from another grid by dragging (MoveRowsToGrid).
Since 14.0 the
paste is set if calling when pasting row.
upd 7.0 API method TRow
AddRow
(TRow parent, TRow next, int show = 0, string id = null, string Def = null)
Adds new empty row to grid and returns it.
If
show&1, the new row is also displayed, for false there must be called
ShowRow method to display it.
(new 7.0) If
show&2, the parents are expanded to show the row.
(new 7.0) If
show&4, the row is recalculated, including Gantt chart.
(new 7.0) Call with
show = 7 to completely show the row.
parent is parent row,
next is row below the new row. If
next is null adds new row as the last
parent's child. If
parent and
next are null adds row as the last root row.
Also sets values to new row from its default row (according to
CDef attribute of parent row).
If set
id, sets it to
id attribute, otherwise creates new unique id for the row.
If set
Def, uses this Def as Default row name.
Only variable row can be added.
new 12.0 API method TRow[ ]
AddRows
(int count, TRow parent, TRow next, bool focus = 0, bool test = 0)
Adds
count of variable rows to given position (
parent and/or
next) and returns an array of them. Or returns null for error.
Since 15.0 for backward compatibility if set
count = 0 it adds one row and returns it.
If set
focus, focuses the newly added rows, preserves the focused columns.
If set
test = 1, does
not add the rows, just test if it is possible and returns true or null.
Uses
AddRow and also calls
OnCanRowAdd and
OnRowAdded API events and alerts error if the row cannot be added to given position.
Copying existing rows
<Cfg> bool
Copying
[1]
If existing rows can be copied / duplicated.
If set to
0, the Panel Copy button is hidden and the CopyMenu does not display items for copying.
If set to
0, all
Copy... actions fail but
CopyRow and
CopyRows methods still work.
(Since 10.0) If set to
0, the rows cannot be copied by dragging.
Copying is automatically disabled when set
Adding='0'.
It is not related to Copy&Paste, it is controlled by Pasting.
new 6.4 <Cfg> bool
CopyDeleted
[0]
If copies also deleted rows.
upd 6.0 <I> bool
CanCopy
[1]
If the row can be duplicated and copied.
If set to
0, the Panel Copy button is inactive and all
Copy... actions fail but
CopyRow and
CopyRows methods still work.
The row cannot be also copied by dragging.
It is not related to copying values into clipboard.
upd 12.0 <Header> bool
CanCopy
[0]
Deprecated since 12.0. Use Panel Buttons or Panel value instead to define the panel buttons for header row.
If the Header Panel Copy button is enabled. Header row itself can never be never copied.
<I> string
Copy
Uploaded to server
This attribute is set when used
ChildPaging=3 and the row was created as deep copy of another row, the Copy is
id of the source row.
This attribute is set only if the source row has some children and they were not loaded from server yet (the row was not expanded yet).
The server script must provide deep copy of the children of source (Copy) node to children of this (id) node.
upd 6.0 <C> bool
Copy
[0]
If the default Panel button
Copy /
CopyAll is visible. This button is hidden also if
<Cfg Copying="0"/>. This button is inactive when the row has
CanCopy='0'.
Click to this button shows popup menu for copying and adding rows. The menu is defined by attribute
PanelCopyMenu.
Used only if the Panel Buttons and the cell value are not set.
<Actions>
CopyRow ...FA
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Copies actual or focused row, the new row is placed above the source row.
new 6.0 <Actions>
CopyRowBelow ...FA
Not attached to any event
Copies actual or focused row, the new row is placed below the source row.
<Actions>
CopyTree ...FA
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Copies actual or focused row with all its children, the new row is placed above the source row.
new 6.0 <Actions>
CopyTreeBelow ...FA
Not attached to any event
Copies actual or focused row with all its children, the new row is placed below the source row.
<Actions>
CopyEmpty ...FA
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Copies actual or focused row with all children, but without their cell values, the new row is placed above the source row.
new 6.0 <Actions>
CopyEmptyBelow ...FA
Not attached to any event
Copies actual or focused row with all children, but without their cell values, the new row is placed below the source row.
new 12.0 <Actions>
CopyRows ...FARO
Not attached to any event, but used in Toolbar Add CopyMenu
Copies all focused rows, the new rows are placed above actual row or the focused range.
new 12.0 <Actions>
CopyRowsBelow ...FARO
Not attached to any event
Copies all focused rows, the new rows are placed below actual row or the focused range.
new 12.0 <Actions>
CopyRowsTree ...FARO
Not attached to any event, but used in Toolbar Add CopyMenu
Copies all focused rows with all their children, the new rows are placed above actual row or the focused range.
new 12.0 <Actions>
CopyRowsTreeBelow ...FARO
Not attached to any event
Copies all focused rows with all their children, the new rows are placed below actual row or the focused range.
new 12.0 <Actions>
CopyRowsEmpty ...FARO
Not attached to any event, but used in Toolbar Add CopyMenu
Copies all focused rows with all children, but without their cell values, the new rows are placed above actual row or the focused range.
new 12.0 <Actions>
CopyRowsEmptyBelow ...FARO
Not attached to any event
Copies all focused rows with all children, but without their cell values, the new rows are placed below actual row or the focused range.
<Actions>
CopySelected ...FARO
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Copies selected rows and places them above actual or focused row.
It copies only rows that can be copied in the location. It fails if no selected row can be copied to the location.
<Actions>
CopySelectedChild ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelected, but copies the rows as the first children of actual or focused row.
<Actions>
CopySelectedChildEnd ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelected, but copies the rows as the last children of actual or focused row.
<Actions>
CopySelectedTree ...FARO
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Like
CopySelected, but copies the selected rows with all their children.
<Actions>
CopySelectedTreeChild ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedTree, but copies the rows as the first children of actual or focused row.
<Actions>
CopySelectedTreeChildEnd ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedTree, but copies the rows as the last children of actual or focused row.
<Actions>
CopySelectedEmpty ...FARO
Not attached to any event, but used in Toolbar Add and Panel CopyMenu
Like
CopySelected, but copies the selected rows with all their children, but without their cell values.
<Actions>
CopySelectedEmptyChild ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedEmpty, but copies the rows as the first children of actual or focused row.
<Actions>
CopySelectedEmptyChildEnd ...FARO
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedEmpty, but copies the rows as the last children of actual or focused row.
upd 6.0 <Actions>
CopySelectedEnd
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelected, but copies the selected rows to end of grid (when
<Cfg AllPages='1'/>) or actual page (when
<Cfg AllPages='0'/>).
There are also available actions
CopySelectedEndGrid to copy to the grid end and
CopySelectedEndPage to copy to actual page end.
upd 6.0 <Actions>
CopySelectedTreeEnd
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedEnd, but copies the selected rows with all their children.
There are also available actions
CopySelectedTreeEndGrid to copy to the grid end and
CopySelectedTreeEndPage to copy to actual page end.
upd 6.0 <Actions>
CopySelectedEmptyEnd
Not attached to any event, but used in Toolbar AddChild and Panel CopyMenu
Like
CopySelectedEnd, but copies the selected rows with all their children, but without their cell values.
There are also available actions
CopySelectedEmptyEndGrid to copy to the grid end and
CopySelectedEmptyEndPage to copy to actual page end.
deleted 12.0 <Actions>
CopyMenu ...F
Attached to OnClickPanelCopy, OnClickButtonAdd and OnClickButtonAddChild
Replaced by
ShowMenu action.
Shows popup menu for copying or adding rows. From this menu can be available all adding and copying actions listed above.
The menu items displayed are set by column or row attribute CopyMenu. The menu items captions are set in Text.xml.
new 6.0 deleted 12.0 <Panel><Space cell> string[ ]
CopyMenu
[...]
Replaced by
Menu attribute.
What items (and their order) will be available in menu displayed by CopyMenu action - this actions attached to Panel Copy button and Toolbar Button Add and AddChild by default.
upd 6.4 API event void
OnRowCopy
(TGrid grid, TRow row, TRow source, bool empty)
Called after the row is copied, but before it is displayed.
row is the copied row, source is the
source row.
empty is true if values were not copied.
Since 6.4 it is called also when pasting new row if set CopyPasteRows=1.
new 6.4 upd 10.0 API event bool
OnRowCopyId
(TGrid grid, TRow row, TRow source, bool move)
Called before creating id for the new copied row, the row has already copied the IdNames columns, the other columns will be copied later.
Since 8.1 it can set the row id and return true to not generate the new id.
Since 10.0 move is set when the row is moved from another grid.
chg 7.0 API method TRow
CopyRow
(TRow row, TRow parent, TRow next, bool deep = false, bool empty = false)
Copies one row inside grid. Returns the row copy.
row is the row to copy, it can be also from another grid,
parent is parent row,
next is row below the copied row. If
next is null, places the row as the last
parent's child. If
parent and
next are null, places row as the last root row.
If
deep is true, copies include children, only visible (not filtered, not deleted).
Copies all row and cell attributes. Does
not copy RowSpan.
Since 7.0 it also shows all the changes and tests if the copy is possible due Def / AcceptDef settings.
chg 7.0 upd 12.0 API method TRow[ ]
CopyRows
(TRow[ ] rows, TRow parent, TRow next, bool deep = false, bool empty = false, bool focus = false)
Copies all given rows inside grid. Shows all changes.
rows is array of the rows to copy in this order. The rows can be also from another grid.
parent is parent row,
next is row below the copied rows. If
next is null, places the
rows as the last
parent's children. If
parent and
next are null, places rows as the last root rows.
If
deep is true, copies include children, only visible (not filtered, not deleted).
(since 12.0) If set
focus, focuses the newly added rows, preserves the focused columns.
Copies all row and cell attributes. Does
not copy RowSpan.
Uses
AddRow and also calls
OnCanRowAdd and
OnRowAdded API events.
(since 12.0) Returns all new added rows (but no their children). Or null for error.
In 7.0 was removed parameter dest_grid and rows now can become from another grid.