background of editable cells UITABLE
Show older comments
Hi !
I created an uitable with guide and I would like to change the background of editable cells.
I tried to use the HTML code with the method https://www.mathworks.com/matlabcentral/answers/25038-how-to-change-each-cell-color-in-a-uitable , it works for the background, but I can't change the value of my cell anymore.
Any ideas ?
12 Comments
Adam Danz
on 29 Jul 2019
Check the "ColumnEditable" property values.
Reeny
on 29 Jul 2019
Adam Danz
on 29 Jul 2019
So the ColumnEditable property has changed and you didn't make that change?
Reeny
on 29 Jul 2019
My bet is that "data" is empty
data = {};
data{1,1}
% ERROR: Index in position 1 exceeds array bounds. (r2019a)
Reeny
on 29 Jul 2019
Reeny
on 29 Jul 2019
Have you verified that 'data' isn't empty? One way of doing that is to put a break at the 3rd line within the conditional (at data{1,1}...) and to see the value of 'data' when the code gets to the break.
Another way of doing that is by printing out the value of 'data' just before that line.
if column == 1
colergen = @(color, text) ['<html><table border=0 width=400 bgcolor=',color,'><TR><TD>',text,'</TD></TR></table></html>'];
data = getappdata(handles.uitable1, 'data')
data %will print to command window
data{1,1} = colergen('#33ffff',(data{1,1}))
set(handles.uitable1, 'data', data);
end
If your error message is "Index exceeds the number of array elements (0)." and that error is comming from the line data{1,1} = colergen..., then either "data" is empty or something's going wrong in your colergen() function.
Reeny
on 29 Jul 2019
Adam Danz
on 29 Jul 2019
Something's not lining up, could you show the full copy-pasted error message?
From the partial error message you shared, it looks like the error is happening on row=eventdata.... but that line is before the set(handles...) line so that doesn't make sense.
Reeny
on 29 Jul 2019
Adam Danz
on 29 Jul 2019
Bingo! See answer. Let me know how that turns out.
Accepted Answer
More Answers (1)
Reeny
on 1 Aug 2019
Edited: madhan ravi
on 1 Aug 2019
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!