dynamic button on uitable. Code include. HELP PLEASE!!!

조회 수: 3 (최근 30일)
James Hendren
James Hendren 2013년 6월 27일
I need to add a dynamic remove button to a uitable. The adjustment needs to be made at the botom of the code. Can anyone help please 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'); % create a pushbutton: handles.pushbutton2 = uicontrol('Style','Pushbutton',... 'Units','Pixels',... 'Position',[50 350 80 40],... 'String','Remove Row') %set the action of the pushbutton1 for when it is clicked set(handles.pushbutton1,'Callback',{@AddRow,handles}) set(handles.pushbutton2,'Callback',{@RemoveRow,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) % %set the action of the pushbutton for when it is clicked set(handles.pushbutton2,'Callback',{@RemoveRow,handles}) function RemoveRow(h,e,handles) oRow = get(handles.table1,'Data',newData) delete (newData)
  댓글 수: 1
James Hendren
James Hendren 2013년 6월 27일
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');
% create a pushbutton:
handles.pushbutton2 = uicontrol('Style','Pushbutton',... 'Units','Pixels',...
'Position',[50 350 80 40],...
'String','Remove Row')
%set the action of the pushbutton1 for when it is clicked set(handles.pushbutton1,'Callback',{@AddRow,handles}) set(handles.pushbutton2,'Callback',{@RemoveRow,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)
% %set the action of the pushbutton for when it is clicked set(handles.pushbutton2,'Callback',{@RemoveRow,handles})
function RemoveRow(h,e,handles)
oRow = get(handles.table1,'Data',newData)
delete (newData)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by