フィルターのクリア

How to deselect a checkbox/node in a checkboxtree programmatically

36 ビュー (過去 30 日間)
DenS
DenS 2022 年 2 月 1 日
回答済み: Benjamin Thompson 2022 年 2 月 2 日
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
Benjamin Thompson 2022 年 2 月 2 日
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
Benjamin Thompson 2022 年 2 月 1 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by