MATLAB Answers

How to change a string field in an edit text box using a pop-up menu

2 views (last 30 days)
Haitham
Haitham on 10 Jul 2015
Answered: Haitham on 10 Jul 2015
Hello, I'm new in using GUI, now I'm trying to change some string fields by using a pop-up menu. Basically, I have two radio buttons one of them do activate a pop-up menu but the other one not. When the pop-up menu is activated (which is the default setting), I want to change the string of some edit text boxes so when the user select an element from the pop-up menu the string of the edit text boxes will change according to that. all these objects are located in one button panel. How can I control that and where my code should be written? Thank you
% --- Executes during object creation, after setting all properties.
function Menu_insert_CreateFcn(hObject, eventdata, handles)
% hObject handle to Menu_insert (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
% Choose buttons
Insert_all_names = get(hObject,'String');
Insert_value = get(hObject,'Value');
Insert_name = Insert_all_names(Insert_value);
switch cell2mat(Insert_name) %hObject == handles.Menu_insert
case 'TNMG-22041261'
set(handles.Edit_c2,'String', '4.14*10^8');
set(handles.Edit_cv,'String', '1792');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.01');
set(handles.Edit_beta,'String', '1.18');
set(handles.Edit_gamma,'String', '0.19');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'TNMM-22040871'
set(handles.Edit_c2,'String', '3.82*10^8');
set(handles.Edit_cv,'String', '1719');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.02');
set(handles.Edit_beta,'String', '1.18');
set(handles.Edit_gamma,'String', '0.14');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'TNMG-16040815'
set(handles.Edit_c2,'String', '3.82*10^8');
set(handles.Edit_cv,'String', '1853');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.02');
set(handles.Edit_beta,'String', '1.18');
set(handles.Edit_gamma,'String', '0.14');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'TNMM-16041237'
set(handles.Edit_c2,'String', '1.36*10^9');
set(handles.Edit_cv,'String', '1697');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.39');
set(handles.Edit_beta,'String', '2.31');
set(handles.Edit_gamma,'String', '0.34');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'CNMG-12040861'
set(handles.Edit_c2,'String', '3.34*10^8');
set(handles.Edit_cv,'String', '1717');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.02');
set(handles.Edit_beta,'String', '1.15');
set(handles.Edit_gamma,'String', '0.26');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'CNMG-12041266'
set(handles.Edit_c2,'String', '6.68*10^8');
set(handles.Edit_cv,'String', '1720');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.23');
set(handles.Edit_beta,'String', '2.22');
set(handles.Edit_gamma,'String', '0.61');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'CNMM-12041237'
set(handles.Edit_c2,'String', '6.68*10^8');
set(handles.Edit_cv,'String', '1634');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.23');
set(handles.Edit_beta,'String', '2.22');
set(handles.Edit_gamma,'String', '0.61');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'CNMG-16061215'
set(handles.Edit_c2,'String', '4.19*10^8');
set(handles.Edit_cv,'String', '1769');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.04');
set(handles.Edit_beta,'String', '1.17');
set(handles.Edit_gamma,'String', '0.34');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
case 'CNMG-16060461'
set(handles.Edit_c2,'String', '3.48*10^8');
set(handles.Edit_cv,'String', '1716');
set(handles.Edit_bv,'String', '0.75');
set(handles.Edit_alpha,'String', '3.66');
set(handles.Edit_beta,'String', '1.38');
set(handles.Edit_gamma,'String', '0.19');
set(handles.Edit_c2,'Enable', 'off');
set(handles.Edit_cv,'Enable', 'off');
set(handles.Edit_bv,'Enable', 'off');
set(handles.Edit_alpha,'Enable', 'off');
set(handles.Edit_beta,'Enable', 'off');
set(handles.Edit_gamma,'Enable', 'off');
end
% --- Executes when selected object is changed in uipanel10.
function uipanel10_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel10
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
Choose_value = get(handles.Choose_type, 'Value');
if Choose_value==1
set(handles.Menu_insert,'Enable', 'on');
else
set(handles.Menu_insert,'Enable', 'off');
end

  0 Comments

Sign in to comment.

Accepted Answer

Haitham
Haitham on 10 Jul 2015
I found it! the code should be in the Callback function not in the CreateFcn of the pop-up menu. Thanks

  0 Comments

Sign in to comment.

More Answers (0)


Translated by