CheckBoxTree - Combination of CheckedNodesChangeFcn and SelectionChangedFcn

9 ビュー (過去 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 Center および File ExchangeApp Building についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by