0

I have create uitable in Matlab with drop downmenu. somehow the drop down menu doesn't get updated with switch/case

enter image description here

I tried substituting the switch/case with if else condition. the drop down menu gets updated but it doesn't give me the desired output!

to simulate please run the code below

enter image description here

Any idea or pointers ?

function [] =foouitable()

f = figure('Position',[100 100 400 150]);

% Column names and column format
columnname = {'Available','Options','SubOptions'};
columnformat = {'logical','bank',{'CheckBox' 'SelectSubOptions'}};

% Define the data
d =    {false 'Reconstruction'   'CheckBox';...
    false 'Segmentation'  'CheckBox';...
    false  'ComputerTomography' 'CheckBox';...
    false, 'UltraSound', 'CheckBox';...
    false, 'AcousticEmission', 'CheckBox'};

% Create the uitable
t = uitable('Data', d,...
    'ColumnWidth', {70 120 100},...
    'ColumnName', columnname,...
    'ColumnFormat', columnformat,...
    'ColumnEditable', [true false true],...
    'RowName',[],...
    'CellEditCallback',@edit)

set(t,'Tag','Config_table');

      function edit(src,evt)
            if evt.Indices(2) == 1
                modifyPopup( src)
            end
        end


    % Set width and height
    t.Position(3) = t.Extent(3);
    t.Position(4) = t.Extent(4);


        function  modifyPopup(src)
            id_group_1 = {'A.1';'A.2';'A.3'};
            id_group_2 = {'B.1';'B.2';'B.3'};
            id_group_3 = {'C.1';'C.2';'C.3'};
            id_group_4 = {'D.1';'D.2';'D.3'};
            id_group_5 = {'E.1';'E.2';'E.3'};
            id_default = {'CheckBox'};

            config_data = get(src,'Data');
            selector = config_data(1:5,1);
            selector = cell2mat(selector);



            config_format = get(src,'ColumnFormat');
            if isequal(selector(1),1)
                config_format{3} = id_group_1';
            elseif  isequal(selector(2),1)
                config_format{3} = id_group_2';
               elseif  isequal(selector(3),1)
                config_format{3} = id_group_3';
                elseif  isequal(selector(4),1)
                config_format{3} = id_group_4';
               elseif  isequal(selector(5),1)
                config_format{3} = id_group_5';
            else
                config_format{3} = id_default;
            end

            set(src,'Data',config_data);
            set(src,'ColumnFormat',config_format);
        end
    end

Thanks in advance!

il_raffa
  • 5,090
  • 129
  • 31
  • 36
sssc
  • 1
  • 2
  • Please provide code that reproduces your issue without convoluted uncommenting steps and explain what your desired output is. – sco1 Jul 12 '16 at 14:37
  • I have edited the code as suggested my excaza. When I check one of the checkboxes I want the corresponding drop down menu to show the group values, while other drop down menus should remain unchanged. – sssc Jul 12 '16 at 15:29
  • Why are you modifying `config_format` in your `if` block and not `config_data`? Why are you modifying `'ColumnFormat'` at all? – sco1 Jul 12 '16 at 16:44

1 Answers1

0

Thanks for the hint excaza. I implemented it But the id_group_1 now consist of a 3x3 char array in one of its rows.

[1]    'Reconstruction'        [3x3 char]
[0]    'Segmentation'          'CheckBox'
[0]    'ComputerTomography'    'CheckBox'
[0]    'UltraSound'            'CheckBox'
[0]    'AcousticEmission'      'CheckBox'

enter image description here

as set(src,'Data',config_data); does not permit a cell array. At the moment it seems like I cannot avoid using config_format inside the if/else condition!!

    function  modifyPopup(src)
        id_group_1 =  {true 'Reconstruction'...
            ['A.1'; 'A.2'; 'A.3'];...
            false 'Segmentation'  'CheckBox';...
            false  'ComputerTomography' 'CheckBox';...
            false, 'UltraSound', 'CheckBox';...
            false, 'AcousticEmission', 'CheckBox'};

        id_group_2 =  {false 'Reconstruction'  'CheckBox';...
            true 'Segmentation'  ['B.1'; 'B.2'; 'B.3'];...
            false  'ComputerTomography' 'CheckBox';...
            false, 'UltraSound', 'CheckBox';...
            false, 'AcousticEmission', 'CheckBox'};

        id_group_3 =  {false 'Reconstruction' 'CheckBox';...
            false 'Segmentation'  'CheckBox';...
            true  'ComputerTomography'...
            ['C.1'; 'C.2'; 'C.3'];...
            false, 'UltraSound', 'CheckBox';...
            false, 'AcousticEmission', 'CheckBox'};

        id_group_4 =  {false 'Reconstruction'  'CheckBox';...
            false 'Segmentation'  'CheckBox';...
            false  'ComputerTomography' 'CheckBox';...
            true, 'UltraSound',...
            ['D.1'; 'D.2'; 'D.3'];...
            false, 'AcousticEmission', 'CheckBox'};

        id_group_5 =  {false 'Reconstruction' 'CheckBox';...
            false 'Segmentation'  'CheckBox';...
            false  'ComputerTomography' 'CheckBox';...
            false, 'UltraSound', 'CheckBox';...
            true, 'AcousticEmission', ['E.1'; 'E.2'; 'E.3']};

        id_default = d;
        config_data = get(src,'Data');
        selector = config_data(1:5,1);
        selector = cell2mat(selector);

        config_format = get(src,'ColumnFormat')
        if isequal(selector(1),1)
            config_data = id_group_1;
        elseif  isequal(selector(2),1)
            config_data = id_group_2;
        elseif  isequal(selector(3),1)
            config_data = id_group_3;
        elseif  isequal(selector(4),1)
            config_data = id_group_4;
        elseif  isequal(selector(5),1)
            config_data = id_group_5;
        else
            config_data = id_default;
        end
        %set(src,'ColumnFormat', config_format)
        set(src,'Data',config_data);

    end
   end
sssc
  • 1
  • 2