numbering the entries in the listbox???
Show older comments
hi , I just want to know if I can number the entries in the list box, for example when I add the first entry it will take number 1 and if I add a second entry it will take automatically number 2 and etc..... can that be done??
5 Comments
Geoff Hayes
on 14 Jul 2014
I don't think that there is an automatic way to do this. When adding an entry to the list box, you would have to include the entry number in the string that is being added to the list box selection list.
Jihad Chamseddine
on 14 Jul 2014
Geoff Hayes
on 14 Jul 2014
Yes, that would work...but it isn't automatic:
% get the current list box selections
selections = get(handles.listbox1,'String');
% determine the current length of the selection list
len = length(selections)+1;
% append the new selection to the list
selections = [selections ; sprintf('%d %s',len,char(newSelection))];
% update the list box with the new selection
set(handles.listbox1,'String',selections);
Jihad Chamseddine
on 14 Jul 2014
Geoff Hayes
on 15 Jul 2014
The above is an example only. You would need to provide more context surrounding your GUI (i.e. relationship between the listbox and pushbutton) and/or some code that demonstrates why your code is not working.
Answers (0)
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!