Adding multiple items to a list box in app designer

Hi,
I am trying to add multiple items to the list box. However, it only displays the first item. The screen shot of the result and the code are below. I am in 2019a.
Thank you in advance for any help! :)
app.TrainClassListBox.Items={'30','40'};
app.TrainClassListBox.Items(3)={'60'};

 Respuesta aceptada

Cris LaPierre
Cris LaPierre el 5 de Mayo de 2020
Editada: Cris LaPierre el 5 de Mayo de 2020
Your code adds the new field. Are you getting an error message, or is it just not displaying? Perhaps look into what is entered in app.ListBox.ItemsData? This controls what is displayed in the ListBox. It seems like it is set to 1. Try setting it back to the default (empty brackets).
app.TrainClassListBox.ItemsData=[];

3 comentarios

Simon Barnatt
Simon Barnatt el 5 de Mayo de 2020
Editada: Simon Barnatt el 5 de Mayo de 2020
Hi,
Sorry for the late response. I am in the UK.
The attributes are as follows.
There is no error message, it just won't display the 40 or 60.
Thanks :)
Cris LaPierre
Cris LaPierre el 5 de Mayo de 2020
Editada: Cris LaPierre el 7 de Mayo de 2020
The issue is with how you have entered ItemsData. You are using a 1x1 cell array. Try using the setting I originally mentioned
app.TrainClassListBox.ItemsData = [];
or, if you have a reason to use numbers (users do not see these values), try something like this
app.TrainClassListBox.ItemsData = {1 2 3};
% or
app.TrainClassListBox.ItemsData = [1 2 3];
I also tested the following
app.TrainClassListBox.ItemsData = [1:1000]; % this worked
app.TrainClassListBox.ItemsData = {1:1000}; % This did not
The best thing, then, is to read up more on the ItemsData field so that you can use it as intended.
Working! Thank you! :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 4 de Mayo de 2020

Editada:

el 7 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by