how to use tree in app designer

20 次查看(过去 30 天)
pipor
pipor 2023-9-8
编辑: Adam Danz 2023-9-8
i want to know what is selected or not:
Jow is not selected
Linda is not selected
where can i find this information? ...
this my code in callBack
function Tree_EquitySelectionChanged(app, event)
nodes = app.Tree_Equity.SelectedNodes;
if ~isempty(nodes)
data = [nodes.NodeData];
display(sum(data));
disp(data)
end
end

回答(2 个)

Shoresh Shokoohi
Shoresh Shokoohi 2023-9-8
The code you've provided seems to correctly identify the selected nodes and display some information about them.
Here's a breakdown of your code:
1. `app.Tree_Equity.SelectedNodes` retrieves a list of selected nodes in the `Tree_Equity` tree component.
2. The `if ~isempty(nodes)` condition checks if there are any selected nodes. If there are selected nodes, it proceeds to the next steps.
3. `data = [nodes.NodeData];` extracts the data associated with each selected node. This assumes that each node has a `NodeData` property that contains relevant information.
4. `display(sum(data));` calculates the sum of the data associated with selected nodes and displays it. This step may not be necessary for your specific task, as it doesn't directly relate to determining which nodes are selected.
5. `disp(data)` displays the data associated with each selected node in the command window.
The information you want to extract from the selected nodes is not entirely clear from your code, but you are correctly accessing the selected nodes and displaying the associated data.
If you want to determine which specific nodes are selected and whether their data indicates selection status (e.g., "selected" or "not selected"), you need to examine the structure of the `data` associated with each node. Ensure that the `NodeData` property of each node contains the necessary information to identify whether it is selected or not, and then adjust your code accordingly.
  1 个评论
Adam Danz
Adam Danz 2023-9-8
SelectedNodes indicates which nodes are currently selected (in blue, below), not which nodes are checked.

请先登录,再进行评论。


Adam Danz
Adam Danz 2023-9-8
编辑:Adam Danz 2023-9-8
Look in app.Tree_Equity.CheckedNodes.
SelectedNodes indicates which nodes are currently selected (in blue, below), not which nodes are checked.

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by