フィルターのクリア

Saving strings in to GUI dynamic Listbox in a loop

2 ビュー (過去 30 日間)
Saeed Soltani
Saeed Soltani 2016 年 5 月 27 日
コメント済み: Saeed Soltani 2016 年 5 月 30 日
Hi, I am trying to save a list of words and set them in a GUI listbox dynamically. This is my loop:
L = length(scchildren1)
c= 1;
for z=1:L
A= A+1;
B= A;
B =int2str(B);
B= scchildren1{z}
set(handles.listbox2,'String',B, 'Value', c);
B= str2num('B');
B= B+1;
c= c+1;
end
I don’t know which property of listbox I can access to change line for each save operation. I thought maybe ‘Value’, but false. Now the problem is I am saving all words in one place in each iteration and at the end remains only one. Any idea would be helpful. Thanks

採用された回答

Image Analyst
Image Analyst 2016 年 5 月 27 日
You can't insert just one item into a listbox. You have to send in the whole string. So you need to make up a cell array of strings and then send that in. for what you did, no for loop is needed:
listboxItems = scchildren1(1:z);
set(handles.listbox2,'String', listboxItems );
If you then want to highlight/select a particular item in the listbox, then is when you set the value property:
set(handles.listbox2, 'Value', someIndexYouWant);
Note that if you have multiselect on then someIndexYouWant can be a vector. if it's a single selection listbox, someIndexYouWant must be a single number.
  1 件のコメント
Saeed Soltani
Saeed Soltani 2016 年 5 月 30 日
This is excactly what I should do. Only small correction in your answer, 'L' instead of 'z':
listboxItems = scchildren1(1:L);
set(handles.listbox2,'String', listboxItems );
Thank you for your help ;)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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