numbering in the listbox??

1 回表示 (過去 30 日間)
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 14 日
編集済み: Jihad Chamseddine 2014 年 7 月 15 日
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 件のコメント
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 14 日
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 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
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 件のコメント
Jihad Chamseddine
Jihad Chamseddine 2014 年 7 月 14 日
yes but it didn't work
Jan
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 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