Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primary and foreign key fun with combos and grids?
Message
From
01/07/2002 12:46:16
Vladimir Zhuravlev
Institute of the Physics of Earth,Russia
Moscow Region, Russia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00673883
Message ID:
00673955
Views:
22
>Sorry for the non-descriptive subject! I am having trouble with a form that gets it's data in what must be a fairly common way... I will explain...
>I have a form with a grid and a combo...
>My main table (contacts) contains contact information - name address etc
>My second table (companies)contains companies...
>My third table (links) is (what I call) a junction table - a record will have it's own primary key plus a key of a contact and a key of a company thus enabling a many to many relationship.
>So I move to a contact in the contacts table then query the links table to get a list of all the companies they have links with. I loop through the links table extracting the primaries of the companies into a select in statement that queries the companies table to get the details - this populates the grid and works well.
>Next I populate the rowsource of the combo with all the companies so that I have the ability for a contact to move between companies...
>
>Here begins the problem!
>
>I cannot successfully get the combo to display the currently selected (selected in the grid control) company name... the idea being that the user can click on the grid and it displays the company name in the combo - by changing this to another company I need to save the primary of this new company to the links table
>
>I hope this expains well enough my scenario - I have tried different controlsource for the combo but as I say... no joy
>
>I haven't posted code as this post is probably long enough already but will do if required...


Chris
I do this in the following way
column with combo, sparce .t. ( combo is shown only in active cell)
column bound=.f.
there is relation between parent table ( grid source and chield for rowsorce of the combo , ) In the combo gotfocus
I do
if not parent.key=chield.key or seek(parent.key,'chield','key')
this.displayvalue=chiled.filedtoshow
else
this.displayvalue=''
endif
In click of the combo is regular code
replace parent.key with chield.key in parent
It works for me for years
Best wishes, Vladimir
Setting bound to t cause problem , if chiled table has gaps in the keys
MVP-2006-2011, PHD in Math and Physics ,
host of www.foxclub.ru,
VFP lector at Interface and Microinform companies
Head science researcher of VNIIA Rosatom.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform