CellEditCallBack in popupmenu within a uitable

5 views (last 30 days)
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
Viet-Anh Dinh
Viet-Anh Dinh on 2 Apr 2013
I mean when I change all values in all popupmenu to make it not 'Select'.
It's said in Product Help that "In order for the CellEditCallback to be issued, after modifying a table cell the user must hit Enter or click somewhere else within the figure containing the table. Editing a cell's value and then clicking another figure or other window does not save the new value to the data table, and does not fire the CellEditCallback.". But this seems to be not true. Value in the last popupmenu will not be updated, even when I click somewhere within the uitable.
And because there's still a popupmenu with the value 'Select', then when I press START button, my program will show an error message.
I don't understand what you mean by "set() Enable 'off' for the start button" ???
Viet-Anh Dinh
Viet-Anh Dinh on 3 Apr 2013
this morning I compiled my program and it ran as I thought, I don't know the reason why yesterday it showed error. Maybe I'm a lucky man :v Thanks for your comments ;)

Sign in to comment.

Answers (0)

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!