how to number selections in listbox?

1 回表示 (過去 30 日間)
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 22 日
コメント済み: Joseph Cheng 2014 年 7 月 30 日
hi, I have a listbox and its selections, when i click on the Add layer, a selection will be added in the listbox, now what i want is how to get that selection numbered so when I enter a name of a layer, it will automatically show 1.name of layer etc...... hope you can hekp me guuys and below there's an image so that you can understand well what i want thanks
  3 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 7 月 22 日
Where do you enter a name of the layer? Or, do you just mean how to number the layers when you press the Add New Layer button?
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 22 日
when I click on the add layer, another window opens and asks me for the name of the layer, and when i enter the name, it will be listed in the listbox, so what i want is that it can be listed and numbered automatically in the listbox(1.first layer 2.second layer etc...)

サインインしてコメントする。

回答 (1 件)

Joseph Cheng
Joseph Cheng 2014 年 7 月 22 日
In your latest comment why not in the"add new layer" button callback get the number of entries already in the list box
NumEntries=length(get(handles.listbox1,'String'));
then concatenate the new one with
newlist = [get(handles.listbox1,'String'); {['layer ' num2str(NumEntries+1)]}];
set(handles.listbox1,'String',newlist)
  6 件のコメント
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 30 日
now when i add a layer, the only thing that appears are the numbers but the name of the layer doesnt appear
Joseph Cheng
Joseph Cheng 2014 年 7 月 30 日
Can you supply a snippit of code? What is the line that you are using to set? How am i supposed to help. It is like me asking you why i have no water in my cup without showing you my cup. perhaps i didn't put water in it. Or maybe i have a big hole in it. Or maybe its not my cup.
Why don't you start by double checking whether you're converting the number to a string so you're not making a mishmash of string and number array. That what you're setting to the list box is the correct cell. the debug debugging tool is a good start. put a breakpoint at where you've just created the new list box items and then see what you're writing. is it just numbers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by