How to deselect a checkbox/node in a checkboxtree programmatically

조회 수: 29 (최근 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
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 CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by