GUI question:Change data depending on ListBox choice
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I want to change the color of the button "Pass" according to the choice of the listBox as shown by the code below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164908/image.png)
function list_VIN_Callback(hObject, eventdata, handles)
if strcmp(get(handles.list_VIN,'String'), '...............< Aucun >.............')
set(handles.Pass, 'BackgroundColor','red');
else
set(handles.Not_Pass, 'BackgroundColor','green');
end;
Is this correct what I wrote as code? it deosn't work!
2 Kommentare
Adam
am 6 Jun. 2017
You are setting the BackgroundColor of two different buttons in that code, but you only seem to have one button. What is the tag of the 'Pass' button?
Antworten (2)
ES
am 6 Jun. 2017
What is the tag of the pass button? I think you are trying to set both the 'String' and 'BackgroundColor' property. If yes, you are doing it the wrong way. You can only set properties to a object by using its unique tag.
ES
am 6 Jun. 2017
Bearbeitet: ES
am 6 Jun. 2017
% get(handles.listbox1,'String') returns listbox1 contents as cell array. So the 'if' will not work.
You should instead get the selected content by using
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
The strcmp should be done on contents{get(hObject,'Value')}
0 Kommentare
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!