How to show one value from two popup menu strings
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Cristian Martin
el 13 de Mayo de 2022
Comentada: Cristian Martin
el 15 de Mayo de 2022
Hi,
I want to help me in understanding a situation.
Let's say I have two popup menus with same values (Audi, Mercedes, Skoda) and an edittext box.
We have also 3 person (Maria, Jhon, Nick) who own one or two different cars
If I select one value (Audi) from the popup menu I want in edittext to show the owners (Maria and Jhon)
Also if I select a value (Audi) from the first popup menu and a value (Skoda) from the second popup menu I want in edittext to show who own the cars (Maria, Jhon and Nick)
I know how to extract the values from the pop up menus but I can't figure how to correlate them with variables.
all_choices = get(hObject, 'String');
selected = get(hObject, 'Value');
chosen = all_choices{selected};
set(handles.edit1, 'String',chosen);
Thank you guys!
0 comentarios
Respuesta aceptada
Image Analyst
el 13 de Mayo de 2022
Try this. Assume Audi is the first entry in the car popup, which is on the left, and the popup on the right is for owners. So then do
audiOwners = {'Maria', 'Jhon'};
skodaOwners = {'Maria', 'Jhon', 'Nick'};
% Get car model
selectedCar = handles.popCar.Value;
% Fill owners popup with corresponding list of owners for that model of car.
if selectedCar == 1
% Fill owners popup with Audi owners.
handles.popOwners.String = audiOwners;
else
% Fill owners popup with Skoda owners.
handles.popOwners.String = skodaOwners;
end
If you really want the names in the edit text box instead of a drop down list, then have a loop
audiOwners = {'Maria', 'Jhon'};
skodaOwners = {'Maria', 'Jhon', 'Nick'};
% Get car model
selectedCar = handles.popCar.Value;
% Fill owners popup with corresponding list of owners for that model of car.
if selectedCar == 1
owners = audiOwners;
else
owners = skodaOwners;
end
% Fill owners popup with Audi owners.
str = [];
for k = 1 : length(owners)
str = fprintf('%s\n%s', str, owners{k});
end
handles.edtOwners.Max = 2; % I think you need this for it to allow a multi-line edit text box.
handles.edtOwners.String = str;
But I think it would be confusing for the user to have two dropdown lists, each with the name of only one kind of car.
10 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!