How to find the item order number in List Box in App designer?
Afficher commentaires plus anciens
I have a List box named "Numbers" that has the same 4 items, they all are the number 5. How can I pick the Item3 (The third in order) to change it to 3.
I used [~,idx] = ismember(app.NumbersListBox.Value,app.NumbersListBox.Items);
But I alwyas get to change the first on because the Value are the same.
How can I find inx using "Item number" instead of "Value" ?
Thank you so much
14 commentaires
Adam
le 17 Sep 2019
Surely if you already know the index then just use it where you would use the 'idx' that you extract above (which is always 1). You should just be able to index into the list of items with this.
Faez Alkadi
le 17 Sep 2019
Adam
le 17 Sep 2019
You said you want item 3. That is the 3rd element of the listbox. What were you going to do with 'idx' from your above code? Just use 3 instead of idx as it will be the 3rd item. I haven't really used list boxes in App designer, but at a guess
app.NumbersListBox.items{3}
will return this.
Ankit
le 17 Sep 2019
Hallo Faez,
When your listbox have same values for e.g.
app.NumberListBox.Items = {'5', '5', '5', '5'};
[~,idx] = ismember(app.NumbersListBox.Value,app.NumbersListBox.Items);
The value of idx is always 1.
In case your list box have diff values for e.g. app.NumberListBox.Items = {'1', '2', '3', '4'};
[~,idx] = ismember(app.NumbersListBox.Value,app.NumbersListBox.Items);
The value of idx is selected item.
You have specific use case where all the values are same?
Faez Alkadi
le 17 Sep 2019
Modifié(e) : Faez Alkadi
le 17 Sep 2019
Adam
le 17 Sep 2019
How can you have a general case if all the list items are the same? You have to pick up the index from somewhere, whether you hard-code it as 3 or get it from somewhere else, but the idea is still the same.
Ned
le 18 Sep 2019
How does your app determine which of the numbers to change? user input? Because like Adam said, if you're programming it, you can just select Item 3. otherwise, I'm thinking you could use something along the lines of
find(ismember(app.NumbersListBox.Items,app.NumbersListBox.Value));
to get the index of all the items indicated by ListBox.Value
Faez Alkadi
le 18 Sep 2019
Ned
le 18 Sep 2019
Have you considered using itemsData to index the entries?

This way value always gives you the index, instead of the item.
Faez Alkadi
le 19 Sep 2019
Ned
le 20 Sep 2019
Just have whatever code you have that updates ListBox.Items, also update ListBox.ItemsData with the next index value.
Faez Alkadi
le 20 Sep 2019
Faez Alkadi
le 22 Sep 2019
Seonggon Kim
le 18 Fév 2023
If there are items with same name, is there a way out?
I recommand to use the 'Table' instead 'List Box'.
app.table.Selection
Réponses (0)
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!