Gui table with dropdown problem

2 vues (au cours des 30 derniers jours)
Baha411
Baha411 le 29 Juil 2019
Commenté : Baha411 le 31 Juil 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.

Réponses (1)

Jalaj Gambhir
Jalaj Gambhir le 31 Juil 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 commentaires
Jalaj Gambhir
Jalaj Gambhir le 31 Juil 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 le 31 Juil 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by