Get a list of all UI Components used in GUI

조회 수: 4 (최근 30일)
M D
M D 2016년 11월 25일
편집: M D 2016년 11월 25일
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!

채택된 답변

Adam
Adam 2016년 11월 25일
편집: Adam 2016년 11월 25일
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
M D
M D 2016년 11월 25일
편집: M D 2016년 11월 25일
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! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by