How to disable specific items from a popup menu by using a logical vector of the same length of the string of the popup menu?
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello , I need some help with a problem...
Let's say that I have a cell containing the strings I want for the popup menu, for example
t = cell(1,5);
t{1,1} = 'Hello';
t{1,2} = 'Hi';
t{1,3} = 'Welcome';
t{1,4} = 'Pleased to meet you';
t{1,5} = 'Join us';
and I also have a logical vector
logict = [false true true false true];
after setting the items in the popupmenu by executing
set(handles.popupmenu1,'String',t);
How can I disable some of the items (in this case the 1st one and the 4th one) by using the logical vector logict?
Thank you very much for the help
0 件のコメント
採用された回答
  Image Analyst
      
      
 2016 年 8 月 28 日
        Just do something for the ones that are true. If desired, you could do a warning for the invalid ones:
selectedItem = handles.popup1.Value;
switch selectedItem 
    case 1
        % Do nothing.
    case 2
        % Do something
        fprintf('You selected a valid item %d\n', selectedItem); % Whatever you want.
    case 3
        % Do something
        msgbox('MATLAB is awesome'); % Whatever you want.
    case 4
        % Just warn user
        message = sprintf('You selected am invalid item %d\n', selectedItem);
        uiwait(warndlg(message)); % Whatever you want.
    case 5
        % Do something
        a=10; % Whatever you want.
end
0 件のコメント
その他の回答 (1 件)
  Walter Roberson
      
      
 2016 年 8 月 28 日
        It is not possible to disable individual items in a uicontrol('style', 'popup'). It is only possible to detect that one of them have been selected and to either return without doing anything or else automatically set the Value property to select something else. For example you could use the UserData property to keep a record of the last valid entry selected, and when an invalid item was selected you could set the Value property to the recorded value.
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Startup and Shutdown についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


