Quantcast
Viewing latest article 3
Browse Latest Browse All 18

Re: uitable - 'logical' - checkboxes

"M " <casemremovethisat@uciremovethisdot.edu> wrote in message <iminim$ii$1@fred.mathworks.com>...
> You've probably figured this out by now, but in case anyone else is looking at this question:
>
> For the logicals, you need to add some code to the table's CellEditCallback. Once the user edits the checkbox by checking or unchecking, the table will attempt to store the logical value in its data array, fail, and then go to the CellEditCallback. If you haven't defined the CellEditCallback or have defined it incorrectly, there will be an error and your table data will not be updated, hence the checbox will not register the new status.
>
> Here's an example of a CellEditCallback for a table with logicals:
>
> function mytabletag_CellEditCallback(hObject, eventdata, handles)
> data=get(hObject,'Data'); % get the data cell array of the table
> cols=get(hObject,'ColumnFormat'); % get the column formats
> if strcmp(cols(eventdata.Indices(2)),'logical') % if the column of the edited cell is logical
> if eventdata.EditData % if the checkbox was set to true
> data{eventdata.Indices(1),eventdata.Indices(2)}=true; % set the data value to true
> else % if the checkbox was set to false
> data{eventdata.Indices(1),eventdata.Indices(2)}=false; % set the data value to false
> end
> end
> set(hObject,'Data',data); % now set the table's data to the updated data cell array

Thanks "M".
This is the exact piece of code that enables the user to recover access to checkboxes after having set the data with the set command.

Viewing latest article 3
Browse Latest Browse All 18

Trending Articles