numbering in the listbox??

3 views (last 30 days)
Jihad Chamseddine
Jihad Chamseddine on 14 Jul 2014
Edited: Jihad Chamseddine on 15 Jul 2014
Well I have a push button and a listbox, and I made a code that when I click on the push button, an entry will be added to the listbox,and as long as I click on the push button, more entries will be added etc.... Also I made another push button to remove the entry that I will not use in the list box. and now what I want is when I click on the push button to add an entry and it asks me to enter the name of the entry to number automatically the entries that I add, so when I add a first entry it will be numbered automatically 1 etc...
Here is the code I used for the "Add entry" push button:
% --- Executes on button press in pushbutton3. % Add Layer function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
prompt=('please enter the name of the layer you wish to add: '); name=('input component name'); numlines=1; defaultanswer={''};
% prompt the user for some input answer = inputdlg(prompt,name,numlines,defaultanswer,'on'); % get the current list box selections selections = get(handles.listbox1,'String'); % append the answer to the list selections = [selections ; answer]; % update the list box with the new selection set(handles.listbox1,'String',selections);
and as I said what I want is to find out how to make the numbering of the entries automatically
  5 Comments
Jihad Chamseddine
Jihad Chamseddine on 14 Jul 2014
and I want the numbers to be shown automatically using a code and not to write them manual, hope you understood my problem
Jan
Jan on 14 Jul 2014
@Jihad: Please insert all useful information in the question, and not in comments. You can edit the question easily.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Jul 2014
Didn't we just see this somewhere? Someone told you to use sprintf() to make up the string with the numbers in there. To be robust you can examine what the user typed in and if they put in a number, adjust your ordering. If they didn't, just add it to the end with a number one greater than what's already there.
  2 Comments
Jihad Chamseddine
Jihad Chamseddine on 14 Jul 2014
yes but it didn't work
Jan
Jan on 14 Jul 2014
@Jihad: Then show us, what you have tried and explain the poblems. It is impossible to suggest an improvement to your code based on "it did not work".

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks 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!