Get selection index for DropDown object using AppDesigner

75 visualizaciones (últimos 30 días)
Jim Hokanson
Jim Hokanson el 10 de Nov. de 2017
Comentada: Mario Malic el 19 de Feb. de 2021
Using AppDesigner, how do I access the selected index of a DropDown menu. The Value is the selected string but I can't find anywhere that indicates the selected index. Instead I seem to have to do:
I = find(strcmp(h.Items,h.Value));
Is this really the suggested approach?

Respuesta aceptada

Matt J
Matt J el 10 de Nov. de 2017
Editada: Matt J el 10 de Nov. de 2017
The h.Value property has different behavior depending on how h.Items and h.ItemsData are set up. If you define the ItemsData property to be some sequence of numeric indices i=1:N, then h.Value will be the numeric value of i corresponding to the selection.
  15 comentarios
Erik
Erik el 19 de Feb. de 2021
Thanks on the info on how to get access to a running app.
There is no way in my version to enter the ItemData so that it becomes a numerical array. What ever I do in de compent inspector, the end result is the same (see below). And yes the (single) Value is shown in the inspector as numbers under each other while the ItemData is shown as 1,2,3,4
But, like I said, in the 2020b version, this behaviour fortunately changed apparently
>> app.DropDown
ans =
DropDown (Option 1) with properties:
Value: '1 2 3 4'
Items: {'Option 1' 'Option 2' 'Option 3' 'Option 4'}
ItemsData: {'1 2 3 4'}
Editable: 'off'
ValueChangedFcn: ''
Position: [131 192 100 22]
Mario Malic
Mario Malic el 19 de Feb. de 2021
Oh, I see what you mean now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by