Get selected value instantly from a listbox without clicking it first

I have a listbox on my gui. When I start the programm the first value in the listbox is selected. But the programm only registers a value when you click it first. So is there a way the programm can start my calculation without having to click the first option in the listbox?
A quick fix is to add the command to the OpeningFcn
listbox_Callback(handles.listbox, [], handles);
The problem is: This fix works fine for one listbox, but I have 3 on my gui. So when i add 3 of these commands to my openingfunction i get the error:
Reference to non-existent field
Any ideas how i can fix it?

 採用された回答

Image Analyst
Image Analyst 2016 年 12 月 10 日

1 投票

As long as you filled up your listbox somehow, either in GUIDE or your OpeningFcn(), you can get any item in it without having to have the user click on one. For example to get the second item in listbox #3:
allItemsInListbox3 = handles.listbox3.String; % Get all items from listbox3.
itemNumber2 = allItemsInListbox3{2}; % Extract only the second item from listbox3.

5 件のコメント

Jan w
Jan w 2016 年 12 月 11 日
Do you know how i can get the variable of the list value then?
function listbox_runden_stelle_Callback(hObject, eventdata, handles)
contents=cellstr(get(hObject,'String'));
popupmenu_runden_stelle=contents(get(hObject,'Value'));
if (strcmp(popupmenu_runden_stelle,'10'))
y=1;
elseif (strcmp(popupmenu_runden_stelle,'100'))
y=2;
end
handles.y=y;
guidata(hObject, handles);
I want the y=1 to be logged in. Thanks :)
Jan w
Jan w 2016 年 12 月 15 日
any ideas? sorry if i push but i don't want to get it lost. Hope you understand.
Image Analyst
Image Analyst 2016 年 12 月 15 日
In whatever callback you want, you can get the selected items like this:
selectedItems = handles.listbox_runden_stelle.Value;
Walter Roberson
Walter Roberson 2016 年 12 月 15 日
What does it mean to "get the variable of the list value" ?
Jan w
Jan w 2016 年 12 月 17 日
I just wanted the value not the string of the listbox. Image Analyst solved my problem. Thanks! :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

質問済み:

2016 年 12 月 10 日

コメント済み:

2016 年 12 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by