how to number selections in listbox?

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

Jihad Chamseddine
Jihad Chamseddine 2014년 7월 22일
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일

0 개 추천

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월 23일
when i click on the add layer, I am able to add and put the number of layer that i want os that's not the problem, my problem is when i add the layer and give it the name, i want it to be numbered and that's all becasue adding the layer and naming it is easy and i know how to do it but my problem is in numbering the layer. hope you understand what i need
Joseph Cheng
Joseph Cheng 2014년 7월 23일
편집: Joseph Cheng 2014년 7월 23일
Please expand on what numbering the layer means. I see no difference between the number in the name. What does assigning a number to the layer mean?
I reread your question, and if i understand this correctly again, what i wrote above could have been modified to suit your needs as you can already assign a name to it.
NAME = inputdlg(_____); %my representation on your popup window asking for name;
NumEntries=length(get(handles.listbox1,'String'));
newlist = [get(handles.listbox1,'String'); {[num2str(NumEntries+1) '. ' NAME]}];
set(handles.listbox1,'String',newlist)
such that with the name you enter it will add the next number (1 2 3 4 5) etc.
Jihad Chamseddine
Jihad Chamseddine 2014년 7월 24일
the last code looks awesome and it is what i really need but when i put it in the code it doesn't work , hope you can verify and help me please, and where do I have to put this code? in which callback? or opening?
Joseph Cheng
Joseph Cheng 2014년 7월 28일
What have you tried in modifications (i hope you did not just copy and paste it in), where did you try put it. Since i only have a slight insight into your code i do not know what your variables are called or how things work together.
My sample above is only an example or structure of how it would work. It shows that what you need to do is when you create a new entry you get the number of entries and then concatenate that number to the name of the layer for what shows up in the listbox.
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.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2014년 7월 22일

댓글:

2014년 7월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by