Question

I am using GUIDE in MATLAB R2012b, and have a uitable with editable logical checkboxes. The Cell Edit callback is as follows:

function data_table_CellEditCallback(hObject, eventdata, handles)
row = eventdata.Indices(1);
column = eventdata.Indices(2);
if column ~= 1 % The checkboxes are all in the first row.  
    guidata(hObject,handles);
    return;
end
table_data = get(hObject,'Data');
if table_data(row,column) == true
    table_data(row,column) = false;
else
    table_data(row,column) = true;
end
set(hObject, 'Data', table_data);
handles.checked(row) = table_data(row,column); % Variable holding the data.  
guidata(hObject,handles);
end

When I click one of the checkboxes, I can see that the data in the table gets appropriately updated (both get(hObject,'Data') and handles.checked(row) return the updated value), BUT the actual checkbox in the GUI does not visually become checked. If I click it again, the variables are again updated, but the checkbox remains unchecked.

So the data is being updated, but the GUI is not. What is going wrong here?

Note: The logical checkboxes are set to editable in GUIDE, so this is not the problem.

Was it helpful?

Solution

The array you use to set the 'Data' property of the datagrid would usually be a cell array.

When the callback is executed the values in the array will reflect the current state of the checkboxes. That is, you don't need to set them.

If you do want to set table_data, you should use something like:

 table_data{row,column} = eventdata.NewData;

BTW, I'm assuming you have set the column format to "Logical" in Guides Table Property Editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top