Get a list of all UI Components used in GUI

5 visualizaciones (últimos 30 días)
M D
M D el 25 de Nov. de 2016
Editada: M D el 25 de Nov. de 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!

Respuesta aceptada

Adam
Adam el 25 de Nov. de 2016
Editada: Adam el 25 de Nov. de 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 comentario
M D
M D el 25 de Nov. de 2016
Editada: M D el 25 de Nov. de 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! :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by