use of dropdownlist code
조회 수: 3 (최근 30일)
이전 댓글 표시
I have this code.
S={'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K';'HCOOK';'HCOONa'; 'CaBr2'};
str={'Choose minimum two salts and maximum three salts available'};
result=listdlg('Promptstring',str, 'ListSize', [100,100], 'ListString', S, 'SelectionMode', 'multiple');
% As I dont want the user to select all salts, I dont want the 'select all' option to come up on the screen. What version of this code can I use so that option doesnt come up..
댓글 수: 5
Image Analyst
2021년 12월 26일
@Muazma Ali did you overlook my Answer below in the official "Answers" section? Anything wrong with that?
답변 (1개)
Image Analyst
2021년 12월 26일
편집: Image Analyst
2021년 12월 26일
I don't see anyway to get rid of hte Select All unless you write your own custom GUI for it. But you can loop until they choose 2 or 3 items:
numSelected = 0;
choices = {'NH4Cl'; 'MgCl2'; 'CaCl2'; 'KCl'; 'ZnSO4'; 'NaCl'; 'ZnBr2'; 'CH3CO2K'; 'HCOOK';'HCOONa'; 'CaBr2'};
promptString = {'Choose salts available (minimum of two and maximum of three)'};
while numSelected < 2 || numSelected > 3
result = listdlg('Promptstring',promptString, 'ListSize', [350,200], 'ListString', choices, 'SelectionMode', 'multiple');
numSelected = length(result);
if isempty(result)
% User clicked cancel. Decide what to do in this case after we exit the loop.
break;
end
if numSelected < 2 || numSelected > 3
warningMessage = 'Please select only 2 or 3 items';
uiwait(warndlg(warningMessage));
end
end
if isempty(result)
return; % Exit the whole program.
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Naming Conventions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!