Event for selecting Choice list entrys multiple time

2 ビュー (過去 30 日間)
Fa
Fa 2020 年 8 月 3 日
回答済み: Uday Pradhan 2020 年 8 月 7 日
Hi,
first of all, i want to apologize that i have no code or picture of the program right now, so i will try to explain it.
I have an GUI with an Table. In that table i have a choice list with a drop down menu. For example, if i select Choice 1, a inputdlgAlpha opens and i can type in something. If i select Choice 2 the inputdlgBeta opens and i can type is something. The program recognised the change from default to Choice 1 or to Choice 2 through the CellEdit callback. Now i want to select Choice 1 in the drop down menu and type in values, after that i want to select Choice 1 again and type in another values. But selecting Choice 1 again doesn't activate the CellEdit callback. If i use the CellSelection callback, something happens just by clicking the table, but not Choice 1 or Choice 2.
How can i work around that problem?

回答 (1 件)

Uday Pradhan
Uday Pradhan 2020 年 8 月 7 日
Hi,
The “CellEditCallback” is trigerred when the the content of a table cell is changed. Selecting ‘Choice 1’ or ‘Choice 2’ initially triggers this callback but not for the second time as content of the cell does not change.
You can try changing the content of the cell (with the drop-down menu) to something else like ‘Default’ whenever the user chooses an option. In this way, one can select the same option repeatedly as the content always reverts to ‘Default’. The below code example may help you understand this further :
fig = uifigure;
myData = {'Andrew' 31 'Male' 'Choose'; ...
'Bob' 41 'Male' 'Choose'; ...
'Anne' 20 'Female' 'Choose';};
uit = uitable('Parent', fig, ...
'Position', [100 150 380 100], ...
'ColumnFormat',({[] [] [] {'Choice 1' 'Choice 2'}}), ...
'ColumnEditable',true, ...
'Data',myData); %last column has drop-down menus
uit.CellEditCallback = @edit;
function edit(obj,eventDetails)
value = eventDetails.EditData;
if strcmp(value,'Choice 1')
obj.Data(1,end) = {'Default'}; %Reverts Choice 1 to Default
answer = inputdlg('input 1:'); %Do something with the input
elseif strcmp(value,'Choice 2')
obj.Data(1,end) = {'Default'};
answer = inputdlg('input 2:');
end
end

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by