"Lockywolf" wrote in message <nlmarb$5a$
1...@newscl01ah.mathworks.com>...
Don't update Max back to 1. Instead, keep Max at 2 and set or modify the callback function (accessible via the control's Callback property) to check the Value property and update it to only contain up to a single value. Something along the following lines (untested):
% Note: this is untested pseudo-code!
function myCallbackFunc(hListbox, eventData)
lastValue = getappdata(hListbox, 'lastValue');
value = get(hListbox, 'Value');
if ~isequal(value, lastValue)
value2 = setdiff(value, lastValue);
if isempty(value2)
setappdata(hListbox, 'lastValue', value);
else
value = value2(1);
setappdata(hListbox, 'lastValue', value);
set(hListbox, 'Value', value);
end
end
end
A better solution that preserves the last-selected item needs to rely on the underlying Java component.
I plan to dedicate next week's blog article to this topic, since I believe that the fact that Max-Min>1 can be used for listbox deselection is indeed undocumented (or at the very least under-documented), and so is the use of the underlying Java component. I'll post the link here once the article is live.
Yair Altman
http://UndocumentedMatlab.com