Uitables and widgets question
Afficher commentaires plus anciens
I have 2 questions.
1) Can checkboxes be implemented into the UItable when building a gui.
2) If so, can rows and checkboxes be added dynamically to the UItable.
Réponse acceptée
Plus de réponses (4)
James Hendren
le 25 Juin 2013
0 votes
James Hendren
le 25 Juin 2013
0 votes
14 commentaires
Tom
le 25 Juin 2013
You can use the CellEditCallback of the uitable to let you run functions when the checkbox is clicked on in the same way as you could for the checkbox UI control.
(by the way, it will be clearer for people to read this if you reply to comments rather than replying with a new answer)
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
Just change the size of the data.
set(table_handle,'Data',data_variable)
if you're using GUIDE, table_handle will probably be handles.table1, or something similar.
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
Yes, and you can do that by resetting the data in the table. Are you using a callback to do this? E.g. Pushing a button adds an extra row to the table.
James Hendren
le 25 Juin 2013
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
function Add_Row_To_Table
%create a table:
handles.table1 = uitable('Data',{'a',false;'b' true},...
'ColumnFormat',{[],'logical'},...
'ColumnEditable',[false true],...
'CellEditCallback',@(h,e) disp([e.Indices(1) e.NewData]));
% create a pushbutton:
handles.pushbutton1 = uicontrol('Style','Pushbutton',...
'Units','Pixels',...
'Position',[150 350 80 40],...
'String','Add Row');
%set the action of the pushbutton for when it is clicked
set(handles.pushbutton1,'Callback',{@AddRow,handles})
function AddRow(h,e,handles)
%get old data:
oldData = get(handles.table1,'Data');
nRows = size(oldData,1);
%generate a new row of data:
newRow = {char(97+nRows) logical(rem(nRows,2))};
%add new row to existing data
newData = [oldData;newRow];
set(handles.table1,'Data',newData)
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
Paste that whole thing into a blank .m file and save it - it works for me
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
I just picked it up over time. Be aware that I didn't create that code using GUIDE, I did it manually but used the same handles format that GUIDE uses. You might want to watch the 'Creating a GUI using GUIDE' video in the MATLAB help documentation
James Hendren
le 25 Juin 2013
Tom
le 25 Juin 2013
To do it in GUIDE, you right click on the table, select Table Property Editor, then in the Columns tab there is an option to select what data format each column will take: make it 'logical'.
James Hendren
le 26 Juin 2013
0 votes
Catégories
En savoir plus sur Develop Apps Using App Designer dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!