필터 지우기
필터 지우기

CheckBoxTree - Combination of CheckedNodesChangeFcn and SelectionChangedFcn

조회 수: 3 (최근 30일)
DenS
DenS 2022년 5월 3일
댓글: DenS 2024년 1월 8일
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.

답변 (1개)

Ravi
Ravi 2023년 12월 28일
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
DenS
DenS 2024년 1월 8일
Hi Ravi,
thank you very much for your reply. Your solution sounds good to me and I will try it.
kind regards
Daniel

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by