How to deselect a checkbox/node in a checkboxtree programmatically

36 次查看(过去 30 天)
Hi,
I am using the new prerelease of MATLAB 2022a. For my current project in App Designer I found the checkboxtree-component.
While I integrate this component in my GUI I was wondering how to deactivate checkboxes of single nodes by
code ?
There is nothing explained in the documentation.

采纳的回答

Benjamin Thompson
In my particular mlapp example, if you set a breakpoint on the button push handler you can query the Tree checked nodes property:
app.Tree.CheckedNodes
ans =
4×1 TreeNode array:
TreeNode (Node)
TreeNode (Node2)
TreeNode (Node3)
TreeNode (Node4)
K>> app.Tree.CheckedNodes(2)
ans =
TreeNode (Node2) with properties:
Text: 'Node2'
Icon: ''
NodeData: []
Show all properties
So all four nodes are checked. This is the parent plus three children. In the tree selection change handler you could easily alter the CheckedNodes property for the tree:
app.Tree.CheckedNodes = app.Tree.CheckedNodes(2)
This changes the selection to just the first child node. You may have already done this type of thing in your solution, but you can easily expand on this example for your particular requirements.

更多回答(1 个)

Benjamin Thompson
Not sure whether you mean unchecking any of the checked boxes or deselecting. In the check box utiree, only one node can be selected. The uittree object has properties SelectedNodes and CheckedNotes. You just need to clear the one you want:
app.Tree.SelectedNodes = [];
app.Tree.CheckedNodes = [];
I attached an app demonstrating this.
  1 个评论
DenS
DenS 2022-2-2
I meant unchecking a single checkbox to get a behavior like radiobuttons...so it is a workaround because there is no app-component where you have an combination of both types.
So when you have a checkboxtree like:
header-node
  • Option 1
  • Option 2
  • Option 3
  • Option3_SubOption1 (RadioButton)
  • Option3_SubOption2 (RadioButton)
Because there is no radiobutton behavior I'd like to solve this by "automatic unchecking".
Unfortunately there is no "value" prop so I played around with the CheckedNodes but it is not so handy like "value".

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by