Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grid instead of browse

Status
Not open for further replies.

Akourou

Programmer
Mar 28, 2019
34
GR
hello,

i followed many programmers suggestion to use grid instead of browse.
but i have a question.
how can i show in the grid only some of the records depending on a condition.
do i use SET FILTER? isn't that slow if you have large number of records?

thank you
 
Yes, you can use SET FILTER. And yes, it does tend to be slow if you have a large number of records.

Another option is to create a cursor containing just the records that you want to show. You can do this with SQL SELECT command. For example:

Code:
SELECT * FROM MyTable WHERE <some condition> INTO CURSOR MyCusor

The set the grid's RecordSource to point to the cursor.

This is efficient, but it has the drawback that you can't easily use the grid to edit the underlying table. If the user edits the grid, the edits go to the cursor, not the table. You would have to write additional code to deal with that. But if you just want to use the grid to display data and to let the user navigate a table, this is the best approach.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
thank you Mike,

i thought of sql select but the data needs to be edited.
what are the options to edit the data when using sql select?
 
Code:
USE a.dbf
BROWSE FOR condition
is not faster than
Code:
USE a.dbf
SET FILTER TO condition
BROWSE

And likewise displaying in a Grid.

Because, as I already said on several occasions, a browse is a grid.

That also means all you read about SET FILTER making grids slow is also true for BROWSE FOR.

SET FILTER can get sluggish. I also wrote about that, many years ago. But that typically only begins with 10,000 records or more. Today it can even be better. And through the grid's optimize property a very specific optimization is also turned on for grids. By the way, it's nevertheless .F. by default.

The absoluteöy clean way is to go for a 3 tier architecture, never directly binding grids or browse to DBF files, but using updatable views or cursoradapters.
But as long as you even haven't tried to SET FILTER you're worrying at the wrong stage of your development. The recommendation still is and always will be premature optimization is hindering you to get to your goal. Bottlenecks appear at places you don't necessarily expect them.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top