How to pre-select a value in a list box (GUI)

12 visualizaciones (últimos 30 días)
Yahel Oren
Yahel Oren el 1 de Ag. de 2021
Respondida: Image Analyst el 1 de Ag. de 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!

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Ag. de 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

Más respuestas (1)

dpb
dpb el 1 de Ag. de 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.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by