Get a list of all UI Components used in GUI

3 Ansichten (letzte 30 Tage)
M D
M D am 25 Nov. 2016
Bearbeitet: M D am 25 Nov. 2016
Hi All!
I'm working on a program which has several input fields, takes the filled in information by the user and starts a query to a database with the specified conditions (something like "SELECT * FROM Foo WHERE Field = 'specified value' AND (...)"). The retrieval works fine, but my approach is really cumbersome and errorprone at the moment. Here is how i construct the WHERE-clause:
function where_clause = constructWhereClause(handles)
where_clause = '';
bezeichnung_arr = get(handles.bezeichnung_edit, 'UserData');
if ~isempty(bezeichnung_arr{2})
where_clause = [ bezeichnung_arr{1} '=''' bezeichnung_arr{2} ''''];
end
derivat_arr = get(handles.derivat_popup, 'UserData');
if ~isempty(derivat_arr{2})
if ~isempty(bezeichnung_arr{2})
where_clause = [where_clause ' AND '];
end
where_clause = [where_clause derivat_arr{1} '=''' derivat_arr{2} ''''];
end
My question is: Is there a way to get a list of all ui components of a gui so I can iterate over them and access their "UserData" property in a for-loop? Since there are many edit fields more to come, this approach will not be the best to construct my statement.
Thanks in advance!

Akzeptierte Antwort

Adam
Adam am 25 Nov. 2016
Bearbeitet: Adam am 25 Nov. 2016
doc findobj
doc findall
should work.
You can do e.g.
editBoxHandles = findobj( guiHandle, 'style', edit' );
Obviously you don't have to limit to edit boxes either, you can just get a full list of everything.
  1 Kommentar
M D
M D am 25 Nov. 2016
Bearbeitet: M D am 25 Nov. 2016
Hi Adam!
Thanks for the response. The line
findobj(guihandles, 'style', 'edit' )
somehow returns an empty GraphicsPlaceholder array. Instead, leaving the "parent"-handle parameter out gives me the desired result, like this:
findobj('style', 'edit' );
Nevertheless, thank you for your fast and useful help! :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by