Effacer les filtres
Effacer les filtres

CheckBoxTree - Combination of CheckedNodesChangeFcn and SelectionChangedFcn

11 vues (au cours des 30 derniers jours)
DenS
DenS le 3 Mai 2022
Commenté : DenS le 8 Jan 2024
Hi,
I am wondering about the behavior of the both main callbacks of a checkboxtree (CheckedNodesChangeFcn, SelectionChangedFcn).
I used to define them externaly via an controller class instead of defining directly in app-File (mlapp):
app.OutputTree.CheckedNodesChangedFcn = ...
@(src,event)My_Toolbox_AppControllerClass.checkedChangedFcn(app,src,event);
app.OutputTree.SelectionChangedFcn = ...
@(src,event)My_Toolbox_AppControllerClass.commonValueChangedFcn(app,src,event);
When I do so the behavior when checking a checkbox differs from the direct implementation in the mlapp-File.
Direct Implementation:
Click on a checkbox -> checkbox gets unchecked or checked directly (both callbacks are executed)
External Implementation in Class:
Click on a checkbox -> checkbox stays unchecked or checked (only SelectionChangedFcn is executed)
Click on the same checkbox -> checkbox gets unchecked or checked (only CheckedNodesChangedFcn is executed)
Does anyone know how to deal with this behavior ? I don't want to perform 2 clicks on a checkbox to uncheck/check it and I don't really want to implement the callbacks in the mlapp-File.
Thanks for your held in advance.

Réponses (1)

Ravi
Ravi le 28 Déc 2023
Hi DenS,
I understand that you are facing an issue in defining the callback functions using an external class.
The methods that are defined in the external class should be marked as Static. “SelectionChangedFcn” is called when the user selects a node that is different from the previous one. This is why you would be seeing only “CheckedNodesChangedFcn” executing over and over when the same checkbox is clicked multiple times.
Please find the below sample code for declaring the callbacks in the app and defining the callbacks in the external class.
function startupFcn(app)
app.Tree.CheckedNodesChangedFcn = @(src, evt) AppController.checkedChangedFcn(app,src,evt);
app.Tree.SelectionChangedFcn = @(src, evt) AppController.commonValueChangedFcn(app,src,evt);
end
classdef AppController
methods(Static)
function checkedChangedFcn(app, src, event)
% Handle the checked state change
disp('checkedChangedFcn called');
end
function commonValueChangedFcn(app, src, event)
% Handle the selection change
disp('commonValueChangedFcn called');
end
end
end
To learn more about the callback functions, please refer to the following link.
I hope this solution resolves the issue you are facing.
Thanks,
Ravi Chandra
  1 commentaire
DenS
DenS le 8 Jan 2024
Hi Ravi,
thank you very much for your reply. Your solution sounds good to me and I will try it.
kind regards
Daniel

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by