Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combo Box
Message
 
À
26/10/1998 07:56:10
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Divers
Thread ID:
00150414
Message ID:
00150565
Vues:
15
There's always more than one way to skin an application ;) After trying numerous approaches I like this one the best.

1. Create a view on the table you want to edit with a parameter of the key field = to ?mvarkeyvalue

2. In the forms data environment put both the base table with the order set to how you want the combo to populate, and the view with table buffering = 5 and no data on load.

3. Create 4 properties, keyvalue (value 0), b4keyvalue (value 0), tablename (value = name of the base table) and viewname (value = name of the view).

4. Create a method, mthMakeList, that populates the combo and put the key field value into one of the combo's columns.

THISFORM.mthMakeList
THISFORM.cboList.Clear
tfile = THISFORM.tablename
SELECT &tfile
t=1
SCAN
THISFORM.cboList.AddListItem(fieldname, m.t, 1)
THISFORM.cboList.AddListItem(fieldname, m.t, 2)
THISFORM.cboList.AddListItem(STR(keyvalue field name), m.t, 3)
THISFORM.cobList.Selected = IIF(&tfile..keyfieldname = THISFORM.keyvalue, .T., .F.)
t = m.t + 1
ENDSCAN

5. Set the column widths of the combo to xx,xx,0 (assuming that column 3 had the key field value.

6. Add your controls to form and bind the fields you want to edit to the view, with all of them enabled = .F.

7. In the interative change event of the combo put this (assuming column 3 is your keyfield value:
mvarkeyvalue = THISFORM.mycombo.List(THISFORM.mycombo.ListItemID,3)
THISFORM.b4keyvalue = THISFORM.keyvalue
THISFORM.keyvalue = m.mvarkeyvalue
=REQUERY(THISFORM.viewname)
THISFORM.refresh

7. At the bottom of the form I put these commands buttons
NEW(visble) EDIT(visble) SAVE(invisble) UNDO(invisble) EXIT(visble)

New INSERTS a new record into the view, enables the controls and disables the combo, and makes New, Edit, Exit invisible and Save, Undo Visible.

Edit makes enables the controls, disables the combo, and makes New, Edit, Exit invisible and Save, Undo Visible.

Save executes TABLEUPDATE(.T., .T., THISFORM.viewname), disables the controls, makes combo enabled, and runs mthMakeList and makes New, Edit, Exit visible and Save, Undo invisible.

Undo executes TABLEREVER(.T., THISFORM.viewname), disables the controls, makes combo enabled, sets THISFORM.keyvalue = THISFORM.b4keyvalue and runs mthMakeList, makes New, Edit, Exit Visible and Save, Undo Invisible .

Exit releases the form with the UNLOAD event having RETURN THISFORM.keyvalue.

Once it's all done, "Save As" to your library file as mytableeditform. Then edit mytableeditform, remove the table and view from the data environment and remove all the bound controls (leave the command buttons). When you need another form to edit a table, pull it in, set the value of the properties "tablename" and "viewname", add the table and view to the data environment, add the controls you want and bind them to the view and whala...she worka'.
Ken Sorce
Team RAD, Inc.
Rapid Application Developers
Ken@TeamRAD.com
www.teamrad.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform