Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBLookupComboBox and prechosen values?

Status
Not open for further replies.

Kudel

Programmer
Dec 3, 2002
36
0
0
NO
Hi

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?

Any help will be greatly appreciated!


-Kudel
 
Set DepartmentID in the OnNewRecord event of the dataset. (Note set DepartmentID field, not the lookup field).

Good luck
 
Hi

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;

//Sets the comboboxes
dblDepartment.ListSource := dsDepartment;
dblDepartment.ListField := 'Department';
dblDepartment.KeyField := 'DepartmentID';

dblCompany.ListSource := dsCompany;
dblCompany.ListField := 'Company';
dblCompany.KeyField := 'CompanyID';

Thanks

 
Hi Kudel,

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 ).

Cheers,

Andrew
 
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.
 
Check out:

How to use Look Up fields with Tables /Queries
faq102-1212

Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top