Adding multiple items to a list box in app designer

조회 수: 4 (최근 30일)
Simon Barnatt
Simon Barnatt 2020년 5월 4일
편집: Cris LaPierre 2020년 5월 7일
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'};

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 5월 5일
편집: Cris LaPierre 2020년 5월 5일
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
Cris LaPierre
Cris LaPierre 2020년 5월 5일
편집: Cris LaPierre 2020년 5월 7일
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.
Simon Barnatt
Simon Barnatt 2020년 5월 5일
Working! Thank you! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by