CheckBoxTree - Combination of CheckedNodesChangeFcn and SelectionChangedFcn
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Ravi
el 28 de Dic. de 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.
CheckBoxTree Properties - https://www.mathworks.com/help/matlab/ref/matlab.ui.container.checkboxtree-properties.html
I hope this solution resolves the issue you are facing.
Thanks,
Ravi Chandra
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!