Hi, I am trying to create a dropdown list search in AppDesigner, that look for a string within the word, not just at the start.
Afficher commentaires plus anciens
My list is hundred of chemicals long and I want to search a dropdown list which will show me all these options containing the word formaldehyde, not just those starting with the word.
I tried this (an answer for a similar question) and it restricts the list as required, but I still only get the options starting with 'formald' come up in my dropdown.
app.NameLookupDropDown.Value = 'formald'
if isempty(app.NameLookupDropDown.Value) % If empty
app.NameLookupDropDown.Items = app.ChemList; % whole dataset
else
idx = contains(app.NameLookupDropDown.Items, app.NameLookupDropDown.Value);
Filtered_Values = app.NameLookupDropDown.Items(idx);
app.NameLookupDropDown.Items = Filtered_Values;
end
----
Formaldehyde
Formaldehyde polymer with 4-(1,1-dimethylethyl)phenol
Formaldehyde mixt. with methylphenol
Sodium formaldehydesulfoxylate
Naphthalenesulfonic acid, polymer with formaldehyde, sodium salt
4-tert-Butylphenol formaldehyde resin
Paraformaldehyde
N-[4-[[4-(dimethylamino)phenyl]phenylmethylene]-2,5-cyclohexadien-1-ylidene]-N-methylMethanaminium chloride, mixt. with formaldehyde
Pentanedial, mixt. with alkylbenzyldimethylammonium chlorides, ethanedial and formaldehyde
3 commentaires
That's odd. I would think, from this code, that you get everything that matches formaldehyde but doesn't begin with "Formald," because contains is case-sensitive by default.
Are you sure the dropdown items contain the whole name in one cell, or is it possible each item is broken up into multiple words?
Tracy Clark
le 8 Nov 2022
It's difficult to diagnose without the full code, but a simple fix might be adding 'IgnoreCase',true to the contains call.
idx = contains(app.NameLookupDropDown.Items, app.NameLookupDropDown.Value, 'IgnoreCase',true);
On the other hand, since your code isn't working as it seems like it should, you might try Marcel's example, or troubleshoot.
You can put a breakpoint at the start of the if block, and when the program pauses, switch to the Matlab IDE window to inspect the app/variable properties. Determine whether they match what you expect to see, and you can inject code via the command window, to make sure the command you want to use is working properly.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




