Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid Control on forms
Message
De
19/07/2001 22:01:59
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00532808
Message ID:
00532938
Vues:
10
>I have a form on which i have a grid control ( for a one to many relationship). When I try and add a record to more than one line in the grid control(to the child) I am unable to. I first have to save the current record and then add again. How can I change this?
>
>Also, each time I try and add a new record, a screen pops up that ask if I want to add to the parent table, child table, or both. How do I get rid of this, so that it will automatically accept that I am going to add to both tables. I am using the standard record navigation buttons I found in the Component gallery.
>
>Thanx Stuart



Well, some points you need to handle:
- Table Buffer Mode is 5, not 3 (Whole table buffer)
- Duplicate primary key problem

Table Buffer:
Correct table buffer mode make it useful on grid data entry.
Because user may access the non-new record and want to save them all.
For Buffer 3, it cause problem (blank record) with save when change record(different row)

Duplicate Primary Key:
In general, you will set a Combine Field as Primary Key.
For example, ALLTRIM(Order_ID)+CHR(9)+ALLTRIM(ITEM) as a PK.
If user add 2nd record with same primary key, it will give 1884 error# and
force you take away that record.



My suggestion is better add record 1 by 1 with some key help to fast add next record:
If sudden program crash, most records are saved.

My current job is switch the CmdAdd button Caption to handle adding records:
Sample code below:
* Thisform.CmdAddOrditems.Click

#DEFINE CAPADDITEM  "\<Add OrdItems"
#DEFINE CAPFINITEM "Finish \<Add"
#DEFINE CAPUPDITEM "Update OrdItems"
#DEFINE CAPCANITEM "Canc\<el Add"

ThisForm.Lockscreen = .T.

IF THIS.CAPTION = CAPADDITEM
* start add
SELECT Orditems
APPEND BLANK
REPLACE Orditems.ORDER_ID with Orders.ORDER_ID
ThisForm.GrdOrditems.Column2.SetFocus

ELSE
* finish add code here
IF TableUpdate(.T.) = .F.
   Messagebox([Add Record fail], 16, [CapAddOrditems.Click error msg])
ENDIF
ENDIF

ThisForm.LOCKSCREEN = .F.

*------------------------------------------------------------------------------------------------------*

* ThisForm.KeyPress()   With setting KeyPreview as .T.
LPARAMETERS nKeyCode, nShiftCtrlAlt

#DEFINE CAPFINITEM "Finish \<Add"

DO CASE
CASE nKeyCode = 13   && Return key

    IF ThisForm.ActiveControl.Name = ThisForm.GrdOrditems.NAME
    * Grid in focus
       IF INLIST( ThisForm.GrdOrditems.ActiveColumn, 4, 5, 6, 7)
       * some column in focus which suppose user already fill in userful data.
           IF ThisForm.CmdAddOrditems.CAPTION = CAPFINITEM 
               Thisform.CmdAddOrditems.Click     &&  Finish Add
               Thisform.CmdAddOrditems.Click     &&  Add new now
       ENDIF
    ENDIF
ENDCASE



User will be add grid record with easy fill in some important data and
press {return} to fill in next record.

Hope above code gives you a general idea on handle add records.
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform