numbering in the listbox??
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Jan
2014년 7월 14일
@Jihad: Please insert all useful information in the question, and not in comments. You can edit the question easily.
답변 (1개)
Image Analyst
2014년 7월 14일
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
Jan
2014년 7월 14일
@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".
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!