Solved

go to record in DBLookUpComboBox

Posted on 2007-04-01
7
879 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
Industry Leaders: 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 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