How to pre-select a value in a list box (GUI)
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yahel Oren
am 1 Aug. 2021
Beantwortet: Image Analyst
am 1 Aug. 2021
I would like to pre-select a value (lets say - value number 45 in an array is the default value) and when I open the GUI I want that value to be selected (with the blue mark in the list box)
I tried to set the Value to my value but it's not working
Thank you!
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 1 Aug. 2021
You can set the index of the listbox in your startup code, yourApp_OpeningFcn() if you're using GUIDE.
index = 45;
handles.listbox1.Value = 45;
If you prepopulated the listbox with strings and want to find out which one(s) has 45, you can do this:
listBoxItems = handles.listbox1.String; % e.g. {'4'; '45'; '5'; '45'}
pattern = '45';
indexes = ismember(listBoxItems, pattern) % e.g. 0 1 0 1
handles.listbox1.Value = find(indexes) % e.g. 2 4
0 Kommentare
Weitere Antworten (1)
dpb
am 1 Aug. 2021
You mean a listdlg box? The 'InitialValue' property (default value 1) is the index to the selected element(s) when the box is opened.
If 'SelectionMode' is 'single' then it is a scalar index value, if 'multiple' it can be a vector of indices.
Again, it is the index to the desired value(s), NOT the value itself, at it is not the value returned which is also an index, not a value.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!