Remove Items
古いコメントを表示
How I can Remove a specific Items from listbox ??
採用された回答
その他の回答 (1 件)
Maryam Emad
2011 年 12 月 15 日
0 投票
8 件のコメント
Image Analyst
2011 年 12 月 16 日
You will need to set the value of the listbox to something less than "end". For example, if the listbox "string" property had 10 cells (items) in it, and you clicked on the last one, so now the "value" property has a value of 10, then if you delete the 10th item and try to stick it back it, the string property will have only 9 cells, but your value property still has a value of 10, which is beyond the end of the list which now has only 9 items in it. So you'd need to set the value property to some value between 1 and 9 (i.e. the old "end" minus 1) so that the selected item is a valid item number. The value property doesn't automatically get updated for the new list. If you don't, your listbox won't appear. Does that explain it? It's like what Walter said but I'd set the value property instead of the ListboxTop property.
Amani
2011 年 12 月 19 日
Thanx aloot ,,
but I'm not understand ><
maybe you mean that ?
currentItems = get(handles.listbox1, 'String');
rowToDelete = get(handles.listbox1, 'value');
newItems = currentItems;
newItems(rowToDelete-1) = [];
set(handles.listbox1, 'String', newItems)
right :\ ?
Walter Roberson
2011 年 12 月 19 日
I would not think so, no.
currentItems = get(handles.listbox1,'String');
rowtoDelete = get(handles.listbox1, 'Value');
newItems = currentItems;
newItems(rowToDelete) = [];
set(handles.listbox1, 'String', newItems, 'Value', 1);
Image Analyst
2011 年 12 月 19 日
No. Try this (untested):
currentItems = get(handles.listbox1, 'String');
% Store which items they highlighted.
rowToDelete = get(handles.listbox1, 'value');
% Deselect any items to prevent problems after deletion.
set(handles.listbox1, 'Value', []);
% Initialize new list to be the same as the old list.
newItems = currentItems;
% Remove highlighted items from the list
newItems(rowToDelete) = [];
% Send shortened list back to the listbox control.
set(handles.listbox1, 'String', newItems);
% Select the first item on the list.
if ~isempty(newItems)
if length(newItems) >= 1
set(handles.listbox1, 'Value', 1);
end
end
Walter Roberson
2011 年 12 月 19 日
Value of 1 is legal when the String is completely empty, so there is no need to do the checking shown above: just setting to 1 like I showed will work.
Amani
2011 年 12 月 19 日
Thaaaaanx alot Walter .. it is okaaay now ^_^
thanx thanx Image Analyst : )
Jihad Chamseddine
2014 年 7 月 14 日
I don't know if you guys are still in this page, but I want to ask you if I want when I remove an item from the listbox so they will be renumbered automatically, can that be done? for example I have items numbered from 1 to 10, so if I delete the item 7, I want that the numbers will be renumbered. hope you can help me guys
Image Analyst
2014 年 7 月 14 日
You're going to have to use something like sscanf() to parse the number out of the line of text. Basically strip off the numbers and rebuild your list from scratch with new numbers.
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!