CellEditCallBack in popupmenu within a uitable
5 views (last 30 days)
Show older comments
First, I want to say that I have read a number of topics about popupmenu and CellEditCallBack in uitable but I haven't found the answer for my problem. So, I raise a question here.
I created a uitable in my figure. In this table, I have nUE rows and each row has 2 columns, one fixed and one editable that is popupmenu. Popupmenu has 4 options: {'Select' 'Voice' 'Data' 'Video'}. The initial option is set to 'Select'. And I let users to change the value for each popupmenu such that if there's any 'Select' option, there's an error message showed up when they press a START button.
My solution is that whenever users change the value in popupmenu, a CellEditCallBack function is activated. It will save the data of the figure at that moment(guidata), increase the number of edited time (editCount) by 1. Then, it will scan all the rows in 2nd column, if there's any 'Select' option, the complete flag is set to false (defService = 0). And in START button CallBack, if defService = 0 then error.
Here is my source code:
tableData = cell(nUE,2);
for ue = 1:nUE
tableData{ue} = num2str(ue);
tableData{ue+nUE} = 'Select';
end
data.service = uitable('Parent',fig,...
'Position',[1030 365 220 322],...
'Data',tableData,...
'FontSize',10,...
'ColumnName',{'User','Service'},...
'ColumnFormat',{'char',{'Select' 'Voice' 'Data' 'Video'}},...
'ColumnEditable',[false true],...
'ColumnWidth',{109},...
'RowStriping','on',...
'RowName',[],...
'CellEditCallBack',@editService_Callback);
guidata(fig,data);
function editService_Callback(varargin)
guidata(fig,data);
editCount = editCount + 1;
tableData = get(data.service,'Data');
if editCount >= nUE
defService = 1;
for ue = 1:nUE
if strcmp(tableData{ue+nUE},'Select')
defService = 0;
break;
end
end
end
end
function start_Callback(varargin)
if ~defService
msgbox('Please DEFINE SERVICE FOR ALL USERS','Error','error');
return;
end
% do stuff
end
I know there's a problem with the last cell edited but it's acceptable for me to click another point in the uitable to update the value. The problem is even when I clicked another point in the uitable when I finished editing, changing all the value not 'Select', there's still an error message.
Could somebody help me with any idea? Or give me any example of using CellEditCallBack to update values in popupmenu into 'Data' of a uitable?
3 Comments
Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!