app designer ui table drop down selection
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Jimmy Zhan
 el 17 de Jul. de 2020
  
    
    
    
    
    Editada: Andrea Carignano
      
 el 19 de Mzo. de 2021
            Hi,
How can I make cells inside App Designer UITable selectable via drop down menu only but not editable as string?
i.e. I need to limit the possible values of these cells using drop down selection to a list of categorical array, and not letting user type whatever they want.
Thanks
0 comentarios
Respuesta aceptada
  Rachel Surridge
      
 el 17 de Jul. de 2020
        
      Editada: Rachel Surridge
      
 el 17 de Jul. de 2020
  
      Hi Jimmy,
You can achieve this by making your categorical array protected. Example:
B = categorical(A, 'Protected', true)
This will protect your drop-down menu from edits. 
Full implementation of an example:
fig = uifigure;
myData = {'Andrew' 31 'Male'; ...
    'Bob' 41 'Male';  ...
    'Anne' 20 'Female';};
myData = cell2table(myData, 'VariableNames', {'Name', 'Age','Gender'});
myData.Group = categorical({'Group 1'; 'Group 2'; 'Group 3'}, 'Protected', true);
uit = uitable('Parent', fig, ...
    'Position', [100 150 380 100], ...
    'ColumnEditable',true, ...
    'Data',myData);
3 comentarios
  Andrea Carignano
      
 el 15 de Mzo. de 2021
				It does not work for me. It works only if the groups are as many as the rows of the table. For example if I have
myData.Group = categorical({'Group 1'; 'Group 2'; 'Group 3';'Group 4'}, 'Protected', true);
I get this error
Error using myscript (line 6)
To assign to or create a variable in a table, the number of rows must match the height of the table.
Ideas?
  Andrea Carignano
      
 el 19 de Mzo. de 2021
				
      Editada: Andrea Carignano
      
 el 19 de Mzo. de 2021
  
			The correct way to do this is:
myData.Group = categorical({'Group 1'},{'Group 1'; 'Group 2'; 'Group 3'}, 'Protected', true);
Más respuestas (0)
Ver también
Categorías
				Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!