Solved

go to record in DBLookUpComboBox

Posted on 2007-04-01
7
866 Views
Last Modified: 2008-01-09
I need to go to a certain record in a DBLookUpComboBox...
So I have 2 tables ,
the first one is called tableone has the fields:
soc,name   (soc is primary key and it's string)

the second one named tabletwo and has the fields
date, id, no, soc (id is primary key)

Tableone is connected with a datasource to a DBLOOKUPCOMBOBOX showing the "name" field
and tabletwo (through a query) is connected to a DBGrid

When the user selects (doubleclicks) a record in the DBGrid I must show the corresponding value in the DBLookUpComboBox

How can I do that?
0
Comment
Question by:Ghitza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 3

Author Comment

by:Ghitza
ID: 18832175
Say the following example of table contents:
tableone:
soc      |    name
---------------------------
"soca" |  "first soc"
"socb" | "second soc"
"socc" | "third soc"
"socd" | "fourth soc"
... and so on

table two has following contents:

date             |    id  |   no   |    soc
-----------------------------------------------
01/01/2005  |  15   | "11"  |   "soca"
02/01/2005  |  23   | "12"  |   "socd"
03/01/2005  |  7     | "13"  |   "socb"
04/01/2005  |  29   | "14"  |   "soca"

So when the user doubleclicks on the record in tabletwo, let's say record with id=7, the DBLookUpComboBox must go to the "second soc" and display it .

I must use DBLookUpComboBox for tableone

Thanks
0
 
LVL 8

Expert Comment

by:RickJ
ID: 18833918
Try this,
In the double click event of the grid, do the following,
if tableecomponentname.findkey([querycomponentname.fieldbyname('soc').asstring]) then begin
  DBLookUpComboBox.text := tableecomponentname.FieldByName('name').asstring ;
end
else
  ShowMessage('Some error message cuse it cant find it') ;
0
 
LVL 3

Author Comment

by:Ghitza
ID: 18834592
Dear RickJ I do not use a Table component to show the records in the DBGrid. Actually I simplified the reallity, in order to keep it simpler. So in the DBGrid I have a dynamic query. But it allways contain a field called "soc". So basically I cannot use findkey on it.
 And as for assigning a string value to the dblookupcombobox... I did not succeed so far not even with simple strings (not necesarily using your ideea)
"Cannot assign to a read-only property"

So please feel free to come with another ideea., also any of you experts... please help
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:RickJ
ID: 18834603
What type of dataset is your dblookupcombo connected to?
0
 
LVL 8

Accepted Solution

by:
RickJ earned 250 total points
ID: 18834668
OK, sorry I use slightly different components.
You need to use KeyValue.
So your DBLookupComboBox1.ListField would be "Name"
the DBLookupComboBox1.KeyField would be "soc"
So then in the grid doubleclick you would do this,
DBLookUpComboBox.KeyValue := query.FieldByName('soc').asstring ;
0
 
LVL 3

Author Comment

by:Ghitza
ID: 18834742
This is great... thanks.
It works now.
You get the points
Thanks again
0
 
LVL 8

Expert Comment

by:RickJ
ID: 18834763
Thanks.
Glad to help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question