You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to find the item order number in List Box in App designer?
4 views (last 30 days)
Show older comments
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 Comments
Adam
on 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.
Adam
on 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
on 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
on 17 Sep 2019
Edited: Faez Alkadi
on 17 Sep 2019
Adam,
this app.NumbersListBox.items{3} thing will work manual by changing the item nuber manually every time. I need it to be general case.
Hi Falcon;
Yes, I have specific use case where all the values are same.
Thats why when I choose an Item to change I alway change the first Item. I need to find a way to change an Item based on its order in the group not its Value.
Thank you
Adam
on 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
on 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
on 18 Sep 2019
Hi Ned.
I program it on the app interface. And when I pick a part from the list using the curser it just read the Value of the item I picked and find the index of it. I need it to read the place of the item in the list. instead of the Value.
Thank you
Ned
on 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
on 19 Sep 2019
Ned,
This might work. But it will always limit my list length to 4. Is it possible to make in infinity or at least 100,000 with out typing it manually ?
Thank you
Ned
on 20 Sep 2019
Just have whatever code you have that updates ListBox.Items, also update ListBox.ItemsData with the next index value.
Faez Alkadi
on 20 Sep 2019
I solved it to be automatic by making the
app.NumbersListBox.ItemsData=1:1:length(app.NumbersListBox.Items);
So whenever I add an Item, The ItemData length changs automatically.
and then whenever I pick an Item to change, I can find its index as
[~,idx] =ismember(app.NumbersListBox.Value,app.NumbersListBox.ItemsData);
Thank you for your help guys
Faez Alkadi
on 22 Sep 2019
app.NumbersListBox.ItemsData=1:1:length(app.NumbersListBox.Items);
So whenever I add an Item, The ItemData length changs automatically.
and then whenever I pick an Item to change, I can find its index as
[~,idx] =ismember(app.NumbersListBox.Value,app.NumbersListBox.ItemsData);
Seonggon Kim
on 18 Feb 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
Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)