populate a listbox with selected folder doc file names - App designer

4 vues (au cours des 30 derniers jours)
Ely Raz
Ely Raz le 10 Août 2020
Modifié(e) : Adam Danz le 11 Août 2020
How can I populate a listbox with all doc files in a selected folder using a button in App designer?
function selectDocButtonPushed(app, event)
app.selectedPath = uigetdir();
docFileInfo = dir('*.doc')
app.docListBox.Items = docFileInfo.name
end

Réponse acceptée

Adam Danz
Adam Danz le 10 Août 2020
Modifié(e) : Adam Danz le 10 Août 2020
Give this a shot,
docFileInfo = dir(fullfile(app.selectedPath, '*.doc'));
app.docListBox.Items = {docFileInfo.name}';
  4 commentaires
Ely Raz
Ely Raz le 10 Août 2020
Thank a lot. I meant how can I store the one file which is marked/selected in the listbox?
Adam Danz
Adam Danz le 10 Août 2020
Modifié(e) : Adam Danz le 11 Août 2020
Here's what you need to know about the listbox.
1) app.ListBox.Items stores what you seein the list.
2) app.ListBox.ItemsData is used to store optiona info about each item in the list. This is what is returned when you fetch the currently selected item.
3) app.ListBox.Value returns the currently selected ItemsData.
So, what I recommend is to store the file names in Items and the full paths in ItemsData. Then, to get the full path of the selected item, you just need to access the Value property.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by