MATLAB R2017b UIListBox possible bug (ItemsData)
5 views (last 30 days)
Show older comments
Liron Stettiner
on 16 Sep 2019
Answered: Manas Meena
on 30 Sep 2020
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
1 Comment
Ned
on 17 Sep 2019
According to the Documentation for ListBox Properties, "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." so it seems to be working just fine.
Accepted Answer
Manas Meena
on 30 Sep 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!