Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Primary and foreign key fun with combos and grids?
Message
De
02/07/2002 00:30:02
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00673883
Message ID:
00674278
Vues:
18
>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,
Since all companies is in combo it's not value missing problem, right ?

If i'd do it actually I'd keep the companykey in grid's recordsource (not just company names though might be).
For combo would have :
with combo
 .rowsourcetype = 3 && SQL
 .rowsource = 'select companyName, companyKey '+;
  '  from companies'+;
  '  into cursor crsCmps'+;
  '  order by companyName'
 .Columncount = 1 && Assuming you don't want to show key
endwith

*Grid.Aftrerowcolchange
select crsCmps
locate for companyKey = GridRecSource.Companykey && or companyName
combo.listindex=recno()
When user chooses a company from combo directly use crsCmps.companyKey to get the key.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform