MATLAB R2017b UIListBox possible bug (ItemsData)

조회 수: 1 (최근 30일)
Liron Stettiner
Liron Stettiner 2019년 9월 16일
답변: Manas Meena 2020년 9월 30일
Hello, My name is Liron. I use MATLAB R2017b.
I’m currently working on an App Designer GUI, in which I use a UIListBox and assign data to each Item in the list. The three properties related to my bug/issue are ‘Value’, ‘Items’ and ‘ItemsData’. As far as I know:
The ‘Items’ property is a cell/string Array which determines the titles of the user’s possible choices.
The ‘Value’ property is the current chosen Item, highlighted in blue. Obviously, This ‘Value’ has to be the same as one of the ‘Items’.
The ‘ItemsData’ property is a 1-n cell/double array (where n = length(Items)) which allows us to assign additional, hidden data to each item in the list.
PROBLEM: After setting ‘ItemsData’ to be anything else than an empty array, MATLAB mistakenly thinks the ‘Value’ is supposed to be one of the values of the ’ItemsData’(!) array, instead of the ‘Items’ array. In my specific case I’ve set the following:
% BEFORE ASSIGNING THE ‘ITEMSDATA’ PROPERTY:
>> App.nameListBox.ItemsData -> {} % check
>> App.nameListBox.Items = {‘option 1’};
>> App.nameListBox.Value = ‘option 1’; % Works good
% ASSIGNING THE ‘ITEMSDATA’ PROPERTY:
>> S = struct;
>> S.a = 1; % For instance
>> App.nameListBox.ItemsData = S;
>> App.nameListBox.Items -> {‘option 1’} % check
>> App.nameListBox.Value -> (the struct, S, even though I haven’t changed the ’Items’ property at all).
Does anyone have any idea why this happens? Is this a bug of this version of MATLAB? Have I done something wrong? Any suggestions?
Thank you very much. Sincerely, Liron Stettiner

채택된 답변

Manas Meena
Manas Meena 2020년 9월 30일
The ListBox is working as intended and this is not a bug. It is a defined property of ListBox which states that If ItemsData is not empty, then Value must be set to an element of ItemsData, and the list box will select the associated item in the list.”
You may refer to the documentation link below to learn more about the ListBox, Properties which control the appearance and behaviour of a ListBox.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by