필터 지우기
필터 지우기

App Designer: How can I select multiple options in a list box without using control button?

조회 수: 38 (최근 30일)
Requirements:
  • control button should not be used to select multiple options.
  • alternative solution of implementing checkboxes: how can i implement it?

답변 (1개)

Abhilash Padma
Abhilash Padma 2020년 1월 2일
If you don’t want to use control button to select multiple options, you can use checkboxes in table to achieve what you wanted to do. Use a table in app designer with two columns where the first column contains the list items and second column contains the checkboxes. You can use the startupFcn callback of UIFigure to initialize the table values.
See the code below where I have initialized the table values:
function startupFcn(app)
app.UITable.Data = [{'a',false};{'b',false};{'c',false}];
end
Then, you can use the CellEditCallback of UITable which will be triggered when the value in table is changed. So, when you check or uncheck the checkbox. This callback will be triggered. Add a property which maintains the list of all items which have its respective checkbox checked.
See the following code which contains code to add/remove the items from the list of selected items. ‘SelectedItems’ is a property which stores the list of selected items. It is initialized as an empty cell array.
function UITableCellEdit(app, event)
indices = event.Indices;
newData = event.NewData;
if newData
app.SelectedItems(end+1)=app.UITable.Data(indices(1),indices(2)-1);
else
app.SelectedItems(ismember(app.SelectedItems,app.UITable.Data(indices(1),indices(2)-1))) = [];
end
end
  댓글 수: 1
APURAV GUPTA
APURAV GUPTA 2020년 7월 28일
It is giving an error: Conversion to double from cell is not possible for the line
app.SelectedItems(end+1)=app.UITable.Data(indices(1),indices(2)-1);
Can you please help me resolve it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by