Why is uilistbox Multiselect property being ignored inconsistently?
3 次查看(过去 30 天)
显示 更早的评论
I am using the new App Designer in 2016a and have created a uilistbox. The Multiselect property is set to 'on'. When running with a debug flag set multi-selection works, when running normally multi-selection does not work. What is driving this behavior? Are there any workarounds or solutions?
Auto generated code that creates the list box:
app.DaysimeterList = uilistbox(app.HomeTab);
app.DaysimeterList.Items = {'proto 1', 'proto 2'};
app.DaysimeterList.Multiselect = 'on';
app.DaysimeterList.ValueChangedFcn = createCallbackFcn(app, @DaysimeterListValueChanged);
app.DaysimeterList.Position = [526 83 100 299];
app.DaysimeterList.Value = {'proto 1'};
Code that updates the list and is supposed to select all items:
function results = refreshDaysimeterList(app)
daysimeterPaths = app.getDaysimeters;
deviceSns = cellfun(@app.getDeviceSn,daysimeterPaths,'UniformOutput',false);
app.DaysimeterList.Items = deviceSns';
app.DaysimeterList.ItemsData = daysimeterPaths';
if isempty(daysimeterPaths)
app.DaysimeterList.Enable = 'off';
app.DaysimeterList.Items = {'None'; 'detected'};
else
app.DaysimeterList.Enable = 'on';
app.DaysimeterList.Value = app.DaysimeterList.ItemsData(:); % Select all Daysimeters
end
end
The update function is called during the App startup:
% Code that executes after component creation
function startupFcn(app)
app.loadPreferences; % Load the App preferences
app.refreshDaysimeterList; % Refresh the Daysimeter list
end
3 个评论
Meade
2016-4-21
The "Value" method is usually indices, but you're trying to assign it whatever format "ItemsData" is in.
Try changing the last line in your refreshDaysimeterList fnc.
app.DaysimeterList.Value = 1:numel(app.DaysimeterList.ItemsData); % Select all Daysimeters
Does this change your result?
Greg
2017-1-23
The comment by Meade is completely off the mark. AppDesigner documentation clearly states that the 'Value' property is a value of the 'ItemsData' property, or of 'Items' if 'ItemsData' is empty.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!