[GUI] How do you get only one element in a listbox

1 次查看(过去 30 天)
I know you are able to obtain all the elements in a string from the listbox with:
get(handles.listbox1, 'String')
But what if I only want the second or fourth element in the listbox?
Thanks in advance <3

采纳的回答

Image Analyst
Image Analyst 2012-12-17
You have to read in the whole thing anyway. Then get the value property and use that to index into the string.
listboxItems = get(handles.listbox1, 'string');
selectedItems = get(handles.listbox1, 'value');
selectedItem = listboxItems(selectedItems);
  4 个评论
Walter Roberson
Walter Roberson 2012-12-17
Change
listboxItems = get(handles.listbox1, 'string');
to
listboxItems = cellstr( get(handles.listbox1, 'string') );
Shane
Shane 2012-12-17
Thank you soo much Walter I appreciate it!!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by