Is it possible to add a new variable to a popup menu while the GUI is running?

3 ビュー (過去 30 日間)
Hello,
I am writing a code that goes as follows:
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Addition=inputdlg('Please Add New Client Name');
With this code, when the user clicks the push button an input dialog box will pop up for them to add a new client name. I then want to take this client name and add it as a new variable in the previously created pop-up menu. Is this possible?

採用された回答

Walter Roberson
Walter Roberson 2013 年 5 月 23 日
編集済み: Walter Roberson 2017 年 8 月 15 日
current_entries = cellstr(get(handles.popupmenu1, 'String'));
current_entries{end+1} = Addition;
set(handles.popupmenu1, 'String', current_entries);
  5 件のコメント
Libros Construccion
Libros Construccion 2017 年 8 月 15 日
there is a missing quote at third line
Walter Roberson
Walter Roberson 2017 年 8 月 15 日
Good point, Libros Construccion; I have edited the quote into place.

サインインしてコメントする。

その他の回答 (1 件)

Eli Duenisch
Eli Duenisch 2013 年 5 月 23 日
I'm not sure what you mean by 'add it as a new variable in the previously created pop-up menu'. If you want to set the default string that is shown in the dialog box use answer=inputdlg(prompt,dlg_title,num_lines,defAns) and set defAns to your last answer.
  1 件のコメント
Nada Ismail
Nada Ismail 2013 年 5 月 23 日
I want to take the user input and add that as a new variable to the pop-up menu I created.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by