Borrar filtros
Borrar filtros

How to deselect a checkbox/node in a checkboxtree programmatically

36 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Benjamin Thompson
Benjamin Thompson el 2 de Feb. de 2022
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.

Más respuestas (1)

Benjamin Thompson
Benjamin Thompson el 1 de Feb. de 2022
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 comentario
DenS
DenS el 2 de Feb. de 2022
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".

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by