GUI - Choice list. diffrent row - diffrent choices

4 Ansichten (letzte 30 Tage)
Martin Poulsen
Martin Poulsen am 8 Mär. 2019
Beantwortet: TED MOSBY am 2 Jul. 2025
Is it posible to have a 'choice list' row format which has diffrent choices depending on which row acces it?
somthing like:
set(handles.uitable1, 'ColumnFormat',{'logical','char',{'test1','test2','test3'}});
for the choices in the first row, and
set(handles.uitable1, 'ColumnFormat',{'logical','char',{'test4','test5','test6'}});
for the choices in the second row,

Antworten (1)

TED MOSBY
TED MOSBY am 2 Jul. 2025
Hi Martin,
A UITable shows a drop-down menu whenever the cell value is a scalar categorical. Because every scalar can carry its own set of categories, each row can have a different list. Storing each scalar inside a cell array column lets every row carry a completely different set of categories, so the drop-down is row-specific.
Below is a code snippet for your usage:
function dropdown_example
row1Cats = categorical({'test1','test2','test3'});
row2Cats = categorical({'test4','test5','test6'});
optRow1 = row1Cats(1);
optRow2 = row2Cats(1);
T = table( ...
[true; false ], ...
["Row 1"; "Row 2"], ...
{optRow1 ; optRow2 }, ...
'VariableNames',{'Flag','Label','Choice'} ...
);
f = uifigure('Position',[350 300 440 140]);
uit = uitable(f, ...
'Data', T, ...
'ColumnEditable', [ true true true ], ...
'Position', [20 20 400 100] ...
);
end
This outputs the following table:
Here is more information on "categorical" :
Hope this helps!

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by