How to delete items entries in a listbox in appdesigner

조회 수: 7 (최근 30일)
Paramonte
Paramonte 2019년 10월 15일
답변: Deepak 2025년 1월 17일 8:12
We have a listbox with multiple entries, and would want to be able to remove selected entries, for which we though we could use the mouse rifght button, as we had this functionalty already implemented when we used guide to build this UI. It was working well, but we are now updating the UI for appdesigner (seems not to work in appdesigner this right click mouse action)
We may consider other possible ways to be able to remove selected listbox entries besides the right mouse click action.
Thanks in advance

답변 (1개)

Deepak
Deepak 2025년 1월 17일 8:12
We can achieve the removal of selected listbox entries in App Designer by adding a button labeled "Remove Selected" and implementing a callback function for this button. The callback retrieves the indices of the selected items, removes these items from the "Items" property of listbox, and updates the listbox to reflect the changes. This approach provides a straightforward and user-friendly way to manage listbox entries without relying on right-click context menus, which may not be directly supported in App Designer.
Below is the sample App Designer code for the same:
% Button callback function
function removeSelectedButtonPushed(app, event)
% Get selected indices
selectedIdx = app.ListBox.Value;
% Get current listbox items
items = app.ListBox.Items;
% Remove selected items
items(selectedIdx) = [];
% Update listbox items
app.ListBox.Items = items;
% Clear selection
app.ListBox.Value = [];
end
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.

카테고리

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