Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Barak Ros
  Where is Barak Ros?
 TLV
 Israel
 Barak Ros
 To: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
Subject: RE: bound textbox
Thread ID: 164509 Message ID: 164528 # Views: 1 # Ratings: 0
Version: Visual FoxPro 6 Category: Forms
Date: Tuesday, March 18, 2008 9:53:28 PM         
   



> > hi all
> > I have a grid that holds a sql statement.
> > one of the fields in the cursor is f1.
> > f1 is not shown in the grid.
> > I want f1 to be shown in a separate textbox under the grid, so when the user moves to another row in the grid the value in the textbox will change to the corresponding value of f1 of that row.
> >
> > how can I do it, without run some sql because I already have the value in the cursor that is open.
> >
> > thanks
> > Barak
>
>
> Barak,
>
> I take it that you are using .RecordSourceType = 4 and your .RecordSource is an SQL statement. This is one of the reasons why I prefer to use a Grid Cursor (or as Andy calls it "Safe Select".) The idea is to base your grid on a cursor rather than an SQL SELECT statement. Set your grid's .RecordSourceType to 1, and in the form's .Load() create a readwrite cursor that has the same structure as the SELECT statement you are using:
>
>
> CREATE CURSOR MyGridCursor (Field1 I, Field2 C(20), ...)
> 

>
> Now that you have your cursor in place, you can set the grid's .RecordSource = "MyGridCursor" or what ever you called it. Set up your columns the way you want (add checkboxes, etc as needed.)
>
> At this point, you have a perfectly working grid that is running over an empty cursor. All you need do is populate that cursor. Create a new form method - in the VFP menu, Form->New Method and call it "PopulateGrid" (or what ever). In that method, add the following:
>
>
> SELECT ... FROM ... WHERE ... ORDER BY INTO CURSOR Junk NOFILTER
> * This is the SELECT statement that you are currently using as the .RecordSource and 
> * it has the same structure as MyGridCursor.  Note the "NOFILTER" at the end.  This
> * ensures that VFP actually builds a temp table rather than just showing you a filtered
> * view of the table.  
> 
> * Empty the grid cursor of anything that is currently in it
> ZAP IN SELECT("MyGridCursor")
> 
> * Now fill the grid cursor with the data you just SELECTed
> SELECT MyGridCursor
> APPEND FROM DBF("Junk")  && This is why you need that NOFILTER I talked about earlier
> USE IN SELECT("Junk") && don't need this anymore so get rid of it
> 
> * And finally, refresh your grid
> WITH ThisForm.MyGrid
>    .SetFocus()
>    .Refresh()
> ENDWITH
> 
> 
> Now, when ever you need to re-populate the grid, simply issue a call to this method:
> 
> ThisForm.RepopulateGrid()
> 

>
> Now, because you have your grid based on a cursor, you can easily go to that textbox that you have below the grid and set the .ControlSource property to "MyGridCursor.SomeField"
>
> Give it a go and come back here if you have any problems.
>
> Ken
> You shall know the truth - and the truth shall set you free. (John 8:33)

thanks ken and Yuri for your help, axactly what I need
just one question Ken - why is better to use the "safe select", why is it safer than regular cursor?

barak

ENTIRE THREAD

bound textbox Posted by Barak Ros @ 3/18/2008 8:05:45 PM
RE: bound textbox Posted by Yuri Rubinov @ 3/18/2008 8:17:33 PM
RE: bound textbox Posted by Barak Ros @ 3/18/2008 8:29:20 PM
RE: bound textbox Posted by Yuri Rubinov @ 3/18/2008 9:01:11 PM
RE: bound textbox Posted by Barak Ros @ 3/18/2008 8:20:00 PM
RE: bound textbox Posted by Ken Murphy @ 3/18/2008 9:17:14 PM
RE: bound textbox Posted by Barak Ros @ 3/18/2008 9:53:28 PM
RE: bound textbox Posted by Ken Murphy @ 3/19/2008 11:54:10 AM
RE: bound textbox Posted by Cetin Basoz @ 3/19/2008 12:05:03 PM
RE: bound textbox Posted by Mike Yearwood @ 3/20/2008 7:58:06 PM
RE: bound textbox Posted by Ken Murphy @ 3/20/2008 8:04:44 PM
RE: bound textbox Posted by Andy Kramek @ 3/20/2008 8:56:23 PM
RE: bound textbox Posted by Cetin Basoz @ 3/19/2008 11:59:46 AM