> > 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