Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 To: Michael Landrup
  Where is Michael Landrup?
 
 Vietnam
 Michael Landrup
 Tags
Subject: RE: HELP ME
Thread ID: 155228 Message ID: 155253 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Grids
Date: Friday, December 28, 2007 2:18:34 PM         
   


> HELP ME!
> I HAVE 2 TABLE BT(SBT,NOIDUNG,TKNO,TKCO...) & GD(SBT,KHACHHANG,MSDV..)
> I WANT SELECT RECORD INTO A TABLE TEMP THEN SHOW IT ON GRID WHEN START A FORM

You have a number of options open to you, but here is the "best practices" version of how to populate a grid. Begin by creating a "grid cusrsor" in the .Load of your form:
SELECT Bt.Sbt, Noidung, Tkno, Tkco, ..., Gd.Sbt AS Sbt2, Gd.Khachhang, gc.Msdv ;
   FROM Bt ;
   INNER JOIN Gd ON Gd.Sbt = Bt.Sbt ; && or what ever the join fields are
   WHERE .f.
   INTO CURSOR MyGridCursor READWRITE && or what ever you wish to call it.

This will simply give you an empty readwrite cursor that you can use as your recordsourcs for your grid. In the .Init() of the form, you can then:
WITH ThisForm.MyGrid
   .RecordSourceType = 1 && Alias
   .RecordSource = [MyGridCursor]  && or what ever you called it.
ENDWITH

Now, to populate your grid, create a custom form method called ".RepopulateGrid()" (using the VFP menu: Form->New Method) and then add code to repopulate the grid:
ZAP IN SELECT([MyGridCursor]) && get rid of any data that currently exists in your grid cursor.
* Now get the data you want in your grid
SELECT Bt.Sbt, Noidung, Tkno, Tkco, ..., Gd.Sbt AS Sbt2, Gd.Khachhang, gc.Msdv ;
   FROM Bt ;
   INNER JOIN Gd ON Gd.Sbt = Bt.Sbt ; 
   WHERE llSomeCondition ; && what ever your conditions are
   INTO CURSOR Junk NOFILTER
* and add it to your grid cursor
SELECT MyGridCursor
APPEND FROM DBF([Junk])
* Don't need the "junk" cursor any more so get rid of it
USE IN SELECT([Junk])
* Now refresh your grid
WITH ThisForm.MyGrid
   .SetFocus()
   .Refresh()
ENDWITH


Ken
You shall know the truth - and the truth shall set you free. (John 8:33)

ENTIRE THREAD

HELP ME Posted by Bac Nguyen Viet @ 12/28/2007 8:42:21 AM
RE: HELP ME Posted by tushar @ 12/28/2007 11:17:59 AM
RE: HELP ME Posted by Bac Nguyen Viet @ 12/31/2007 2:05:47 PM
RE: HELP ME Posted by surinder singh @ 12/28/2007 11:47:53 AM
RE: HELP ME Posted by Bac Nguyen Viet @ 12/31/2007 2:01:22 PM
RE: HELP ME Posted by Cetin Basoz @ 12/28/2007 1:14:17 PM
RE: HELP ME Posted by Bac Nguyen Viet @ 12/31/2007 2:00:53 PM
RE: HELP ME Posted by Ken Murphy @ 12/28/2007 2:18:34 PM
RE: HELP ME Posted by Bac Nguyen Viet @ 12/31/2007 10:12:16 AM
RE: HELP ME Posted by Ken Murphy @ 1/1/2008 2:46:43 PM