GUI question:Change data depending on ListBox choice

1 回表示 (過去 30 日間)
Samah EL QASSAH
Samah EL QASSAH 2017 年 6 月 6 日
編集済み: ES 2017 年 6 月 6 日
Hi,
I want to change the color of the button "Pass" according to the choice of the listBox as shown by the code below:
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 件のコメント
Adam
Adam 2017 年 6 月 6 日
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?
Samah EL QASSAH
Samah EL QASSAH 2017 年 6 月 6 日
編集済み: Samah EL QASSAH 2017 年 6 月 6 日
Thank you to notify me, I corrected the code
function list_VIN_Callback(hObject, eventdata, handles)
if strcmp(get(handles.list_VIN,'String'), '...............< Aucun >.............')
set(handles.Pass, 'BackgroundColor','red');
else
set(handles.Pass, 'BackgroundColor','green');
end;
When I make a choice VIN1, VIN2 or VIN3 the button "Pass" becomes green but when I chose "....<Aucun>....the" Pass "button does not become red.
%

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

回答 (2 件)

ES
ES 2017 年 6 月 6 日
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.
  1 件のコメント
Samah EL QASSAH
Samah EL QASSAH 2017 年 6 月 6 日
The tag of "Pass" button is Pass

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


ES
ES 2017 年 6 月 6 日
編集済み: ES 2017 年 6 月 6 日
% 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')}

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by