Why does using 'copyobj' function with 'uitreenode' break node selection?

4 views (last 30 days)
I am using 'copyobj' function to copy 'uitreenode' within the same 'uitree'. The interactive node selection within a 'uitree' misbehaves when a 'uitreenode' is copied within its parent 'uitree'. When a node is created using 'copyobj' function, the new node and the node it was created from can both be selected, even if the 'Multiselect' property was turned off.
The behavior also persists if a node is copied to a separate 'uitree' and then the new object's parent set to the original.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Apr 2020
Edited: MathWorks Support Team on 15 Apr 2020
This is a known bug which has been resolved in MATLAB R2018b.
If you are experiencing this issue in MATLAB R2018a or an earlier release, you can use one of the following workarounds:
1. The recommended workaround is to create a custom function to copy 'uitreenodes' as shown below:
function nodeCopy = treeNodeCopyObj(node, parent)
nodeProperties = get(node);
nodeProperties = rmfield(nodeProperties, 'BeingDeleted');
nodeProperties = rmfield(nodeProperties, 'Type');
nodeCopy = uitreenode(parent, nodeProperties);
end
2. Another potential workaround, which is less recommended, is to create a custom 'copyobj' function and put it in your path above the built-in version as shown below:
function nodeCopy = copyobj(node, parent)
if isa(node, 'matlab.ui.container.TreeNode')
nodeProperties = get(node);
nodeProperties = rmfield(nodeProperties, 'BeingDeleted');
nodeProperties = rmfield(nodeProperties, 'Type');
nodeCopy = uitreenode(parent, nodeProperties);
else
builtin('copyobj', node, parent)
end

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!