How to find the item order number in List Box in App designer?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam
2019-9-17
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
2019-9-17
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
2019-9-17
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
2019-9-17
编辑:Faez Alkadi
2019-9-17
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
2019-9-17
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
2019-9-18
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
2019-9-18
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
2019-9-18
Have you considered using itemsData to index the entries?
This way value always gives you the index, instead of the item.
Faez Alkadi
2019-9-19
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
2019-9-20
Just have whatever code you have that updates ListBox.Items, also update ListBox.ItemsData with the next index value.
Faez Alkadi
2019-9-20
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
2019-9-22
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
2023-2-18
If there are items with same name, is there a way out?
I recommand to use the 'Table' instead 'List Box'.
app.table.Selection
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)