I’ve got a user table in my db. Each user got a departmentID. I use a DBLookupComboBox to show the different departments. When I open a user for editing, how can I make his department to be the pre chosen value?
Thank you for responding. I’m not sure of what you mean. Can you please show me in the code below? I want the pre chosen value to be QUser.FieldValues['DepartmentID'].
The beginning of the component names tells you what they are according to this:
ds... = TDataSource
dbl... = TDBLookUpComboBox
Q... = TADOQuery
//Sets the TADOQuerys. QUser is already set.
QDepartment2 := GetQTable('select * from Department where DepartmentID = ' + inttostr(QUser.FieldValues['DepartmentID']),false);
QCompany2 := GetQTable('select * from Department d,Company c where c.Companyid = d.Companyid and DepartmentID = ' + inttostr(QUser.FieldValues['DepartmentID']),false);
//Each query now holds only one post.
//Sets the datasources
dsDepartment.DataSet := QDepartment2;
dsCompany.DataSet := QCompany2;
My guess is that the best choice here( as in most cases ) is
avoiding the use of data-aware controls.
Yes, I know, they spare lots of work but they
make things so that your GUI becomes unchangable and it
ties you to client/server programs rather than n-tier ones.
I strongly advice you don't use data-aware controls.
For more about this, read a Wayne Niddery( TEAMB )
article on the topic, available on the Borland
Community( now BDN ).
At a guess, two choices will work:
use TQuery.Locate to get dsDepartment pointing to the correct record, or (guessing) set the TCombo.ItemIndex directly.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.