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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Filter - allways showing first record

Status
Not open for further replies.

1836

Technical User
Jun 19, 2008
18
HI!,

I am using a grid to show data (recordsource=xyz.dbf). After user selects particular key, I do 'set filter' to that key. The problem is that the first record is allways showing up, even though it does not meet the filter criteria. After scrolling down in the grid & comming back up it disappears. Please help.
 
You should change Record pointer:
Code:
SET FILTER TO .....
GO TOP

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
thanx, i just added a 'go top' after the 'set filter' & i am still getting that first record.
 
It works for me:
Code:
CLEAR
CREATE CURSOR Test (Fld1  INt)
FOR asd =1 TO 40
    INSERT INTO Test VALUES (asd)
NEXT
GO TOP
SET FILTER TO Fld1%2 == 0
? fld1 && 1
GO TOP
? fld1 && 2

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
SET EXACT on
this is my code, contained in the 'Mouseclick' event of a command button:
SET FILTER TO
IF thisform.check_num.value<>SPACE(25)
SET FILTER TO Alltrim(thisform.check_num.value)=ALLTRIM(CHECK_NUM)
ENDIF
GO top
COUNT TO RCTR
IF RCTR=0
MESSAGEBOX("SORRY...NO CHECK'S FOUND")
RETURN
endif
thisform.deposit_list.visible=.t.

I am getting the right number of records, but record #1 allways shows up in the thisform.deposit_list grid
 
How about:
Code:
SET FILTER TO
IF NOT thisform.check_num.value == SPACE(25)
   lcFlt = [Check_Num == ']+PADR(ALLTRIM(thisform.check_num.value,25)+[']
   SET FILTER TO &lcFlt
ENDIF
GO TOP
IF EOF()
   MESSAGEBOX("SORRY...NO CHECK'S FOUND")
   SET FILTER TO
   RETURN
ENDIF
thisform.deposit_list.visible=.t.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Borislav: I changed 1 line of your code to this:
lcflt='val(thisform.check_amount.value)=amount'
(which should do the same thing, your code lcFlt = [Check_Num == ']+PADR(ALLTRIM(thisform.check_num.value,25)+['] was giving me an error) & i still have the same problem.
Myearwood: I addded thisform.deposit_list.refresh()
& the wrong amount does NOT show up, but it displayed from the last record, despite my putting in a 'go top' after the refresh.
 
Two things that I see...

COUNT TO RCTR will result in the record pointer at the bottom of the table (EOF).

You may want to reverse the code line sequence:
Code:
COUNT TO RCTR
GO TOP

Also I do not see where you issue a
ThisForm.MyGrid1.Refresh to 're-paint' your grid.

Good Luck,
JRB-Bldr
 
Let me suggest you not do things this way. With a FILTER, the grid scroll bar will behave erratically because records will be filtered out. This can be very confusing to the user. Instead, use a View and requery the source table.

Craig Berntson
MCSD, Visual FoxPro MVP,
 
Hi.

Instead of using GOTO TOP, use LOCATE FOR .T.

Also, you can use a timer to go to the bottom of the table, and LOCATE FOR .T. after.

But Craig is right. Views are always better to display data in Grids.

Hope it helps

Nro
 
Hello Mike.

I’ve read long time ago that LOCATE FOR .T. with a filter will activate Rushmore. GOTO TOP will not and if the table is big, it may take a while before getting the result. Now, I never try LOCATE alone, maybe because it was not working with Foxbase. Old habits I think.

Nro

 
But I think Rushmore was introduce with Fox 2.0

Nro
 
Nro,

I've read long time ago that LOCATE FOR .T. with a filter will activate Rushmore. GOTO TOP will not and if the table is big, it may take a while before getting the result.

I think you're referring to GO TOP with a filter and an index in force, as in this example:

Code:
USE Customers
SET ORDER TO state
SET FILTER TO state = "CA"
GO TOP

If the table is large, the above code will be very slow. That's because the GO TOP is first going to the first record in index order, then stepping through one record at a time until it finds one that meets the filter condition.

If you remove the SET ORDER TO State, it will run very much faster.

But I think Rushmore was introduce with Fox 2.0

That's correct. I remember going to a launch and seeing Rushmore demonstrated for the first time. I've still got the T-shirt.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hello Mike. My mistake. It's LOCATE, not LOCATE FOR .T. (...). It came from "Hacker's Guide to Visual Foxpro" of Tamar Granor, Ted Roche, Doug Hennig and Della Martin ...

Going Nowhere Fast

.
.
.

SET FILTER TO <optimizable condition>
LOCATE && Same as GO TOP
.
.
.

By the way, the code above works only if there is an index order set. If there might be no order, you have to check for that.


Great book, BTW.

Nro
 
Hi 1836.
After thinking, I had a similar problem with one of my grid. The first time I display the grid with filtered data, all the data is displayed in the grid. If the user click on the grid, or resize the form, the lines disappear. I have no explication for that, and to fix it, I had a timer in my form with interval = 2000

In the timer event, here the code
Code:
WITH THIS
 lcSource = thisform.grdAdresses.RecordSource
 SELECT &lcSource
 LOCATE		&& Go TOP
 thisform.grdAdresses.Refresh()

 .Interval=0

ENDWITH
Also, did you try to open the source, set the filter, go to top, and bind the grid with that source?
Good luck
Nro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top