Selective selection in listbox
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I was looking for a way to control further the possibility of selection (modification of the property 'Value' of a listbox) to make only the items who are present in the listbox. Indeed as seen in the image,
there is only four items in the listbox, but it is possible to select a non existent item by being able to select 'Value' that will be off limit from the box. It happen to cause an error when i use a delete function because of this over permissive selection. After many research on the forum and other place I couldn't manage to find ways to limit the value of the 'Value' property.
Thanks in advance for your help and time.
ps : I'm using the Matlab 2011b version
4 Kommentare
Image Analyst
am 20 Dez. 2017
There were a lot of changes starting with R2014b. What version are you using?
Did my solution below work?
What is handles.counter? Is it supposed to be the number of items in the listbox? Why are you setting the 'Max' property? As I remember it, it was just 1 or 2 depending on whether you want it to be single selection or multiselection, not some arbitrary number.
Antworten (1)
Image Analyst
am 19 Dez. 2017
Try this:
listBoxItems = handles.listbox1.String;
selectedItems = [];
for k = 1 : length(listBoxItems)
if length(strtrim(listBoxItems{k})) > 0
% Only select items that are not all whitespace.
selectedItems = [selectedItems, k];
end
end
handles.listbox1.Value = selectedItems;
2 Kommentare
ET1994
am 17 Nov. 2018
Image Analyst, I want to choose a care from the listbox and set an if statement if one is chosen from the list the corresponding x% appear in a static Text.
Can you help for the coding?
Image Analyst
am 17 Nov. 2018
selectedItem = handles.listbox1.Value
if selectedItem == 3
% Accident, so do whatever. It's the third item after Keyword and a blank line.
elseif selectedItem == 4
% Childbrith, so do whatever.
etc.
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!