現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to find the item order number in List Box in App designer?
10 ビュー (過去 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?
![Screenshot_64.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/238811/Screenshot_64.png)
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)