MATLAB Answers

In one UItable CellselectionCallBack fucntion can i call another UItable CellselectionCallBack function?

13 views (last 30 days)
sachin narain
sachin narain on 24 Apr 2018
Answered: Ameer Hamza on 24 Apr 2018
I have two Uitables .i am checking which cell the user chooses by calling its CellselectionCallBack function and at the same time i want to check which cell the user chooses in the second table also.Is this possible?
Kindly help with this.Any help is appreciated?

  0 Comments

Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 24 Apr 2018
You cannot "call" the callback function. Callback functions are event-driven, and therefore only triggered when the corresponding event occurs. What you want to do it to create a "central" variable that both callback function can access. So whenever a callback is executed, it will write the required value to the "central" variable, which other callback can also access anytime. The given image describe the scheme. Fortunately, every graphic object has a property called UserData which is there for the user to save data inside the graphics object handle. MATLAB itself never uses UserData property. In your case, you can use UserData property of figure object to save the values of selected cells. A general sketch to do this is
function CBuitable1(HObj, event)
selectedCellTable1 = event.Indices;
% access the selected cell of uitable2 from "central" varable as follow
try
selectedCellTable2 = HObj.Parent.UserData.table2;
catch
selectedCellTable2 = [];
end
% also remember to save the indices of Table1 to the "central" variable
HObj.Parent.UserData.table1 = selectedCellTable1;
% do other things you want
end
Similarly, for the second uitable, do it like this
function CBuitable2(HObj, event)
selectedCellTable2 = event.Indices;
% access the selected cell of uitable2 from "central" varable as follow
try
selectedCellTable1 = HObj.Parent.UserData.table1;
catch
selectedCellTable1 = [];
end
% also remember to save the indices of Table1 to the "central" variable
HObj.Parent.UserData.table2 = selectedCellTable2;
% do other things you want
end
Using this mechanism, you can share variables among several callbacks.
%

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.