Effacer les filtres
Effacer les filtres

App Designer ListBox and DropDown selection number

15 vues (au cours des 30 derniers jours)
Jurgens Wolfaardt
Jurgens Wolfaardt le 21 Août 2018
Hi All
I'm a GUIDE user but am now doing my first major GUI with App Designer (in 2017b), due to a nudge from Mathworks.
In GUIDE, the current selection number of a ListBox is extracted by handles.ListBox.Value (and for a DropDown, it is handles.DropDown.Value). In App designer the 'Value' field has been changed to output the content string of the selected entry and not the number of that entry. I can't find any field giving me the number? (which seems a step backwards to me in the context of vectorized code being the way to go)
Currently, I am awkwardly finding the number with strcmp inside a for loop.
for i = 1:length(app.DropDown.Items)
if strcmp(app.DropDown.Items{i},app.DropDown.Value)
break
end
end
SelectNum = i;
How do I obtain the number in a quick way?
Thanks in advance

Réponse acceptée

Ashutosh Prasad
Ashutosh Prasad le 24 Août 2018
Hello
You can use the ItemsData property of the app.DropDown class to specify whether you want the app.DropDown.Value to be numeric or string.
If you want numeric values just change the above code fragment with the following code snippet
>> app.DropDown.ItemsData = 1:length(app.DropDown.Items)
>> SelectNum = app.DropDown.Value;
Let me know if this works for you
  2 commentaires
Jurgens Wolfaardt
Jurgens Wolfaardt le 27 Août 2018
Thank-you. That solves it!
Kristoffer Walker
Kristoffer Walker le 3 Déc 2022
Excellent development option

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by