Why does using 'copyobj' function with 'uitreenode' break node selection?
2 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2018-6-22
编辑: MathWorks Support Team
2020-4-15
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.
采纳的回答
MathWorks Support Team
2020-4-15
编辑:MathWorks Support Team
2020-4-15
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!