Gui table with dropdown problem

3 views (last 30 days)
Baha411
Baha411 on 29 Jul 2019
Commented: Baha411 on 31 Jul 2019
Hi! I am trying to create a GUI with table that includes first column with a dropdown list in each cell. But I keep getting an error. The opening fuction for the uitable is below:
% --- Executes just before GuiTable01 is made visible.
function GuiTable01_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GuiTable01 (see VARARGIN)
% Choose default command line output for GuiTable01
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
Nrows = 40; Ncols = 6;
Data_init0 = cell(Nrows,Ncols);
set(handles.uitable1,'Data',Data_init0); % this creates an empty table
% to create a table with dropdown
Ndropdown = 4;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
tdata = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
set(handles.uitable1,'Data',tdata);
This gives an error message "Error using matlab.ui.control.Table/set
Functionality not supported with figures created with the figure function. For more information, see Graphics Support in App Designer."
However, this is what I am trying to do:
Ndropdown = 4; Nrows = 40;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
tdata = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
fig0 = uifigure; uit = uitable(fig0,'Data',tdata,'ColumnEditable',true);
I appreciate any ideas to fix the code or if there is any other ideas to do what I am trying to do.

Answers (1)

Jalaj Gambhir
Jalaj Gambhir on 31 Jul 2019
Hi,
Unfortunately, this functionality is not available in GUIDE. You can do the same in App Designer by using this code in the startupFcn callback:
Nrows = 40; Ncols = 6;
Data_init0 = cell(Nrows,Ncols);
app.UITable.Data = Data_init0; % this creates an empty table
% to create a table with dropdown
Ndropdown = 4;
dropdown = categorical(ones(Nrows,1),1:Ndropdown,{'Select','HorLayer','VerLayer','Point'});
emp = cell(Nrows,0); % empty cells
newDisplayData = table(dropdown,emp,emp,emp,emp,emp,'VariableNames',{'c1','c2','c3','c4','c5','c6'});
app.UITable.Data = newDisplayData;
app.UITable.ColumnEditable = true;
  3 Comments
Jalaj Gambhir
Jalaj Gambhir on 31 Jul 2019
Hi,
App Designer and GUIDE are two different methods of creating graphic applications in MATLAB. App Designer provides an enhanced UI component set and design environment. You can know more here.
Baha411
Baha411 on 31 Jul 2019
Thanks!
Quick questions... Is this suggesting that the App Designer is better and more advanced? Do you know limitations of each of these options? And is App Designer suggesting that Guide may be removed in future?

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps 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!