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

Empty grid after set key

Status
Not open for further replies.

vanni75

Programmer
Nov 27, 2002
29
BE
Hi ,

I have a grid with as recordsource a table.

I have several buttons on my form , who are setting a key for the table.

Example.

Table : People
set key to "Agents"

After hitting the button the grid is refreshed and the records where the key stands for are showed.

When there are no results the grid shows nothing .. this is normal.

But when I change then the key to something that exist the grid stays empty !! A strange thing is when i go to debug mode and return without doing something the records are shown. Is this a bug?

Can someone help me please ?

THX

 
Hi,

When you set the key do you change the grid's RecordSource? Is that a temporary table that you are using?

If that is the case then when ever you create a new set of records do the following:

Assume the grid's name is called grdPickList.

ThisForm.grdPickList.RecordSource=SPACE(0)
That will keep the structure of the grid, then create the records and re-asign the RecordSource to the table name.

Regards,

Doron


The Farber Consulting Group, Inc.

The Creator of VisualRep - Report and Query Engine
 
Hi ,

It's a table that I use.

And the only thing I do is setting a key

just like this

select tablename
set key to 'Agents'
thisform.gridname.setfocus()
thisform.gridname.refresh()

and then the grid shows no records (unless I go to the debugger and return back )

It just like the are not displayed... but they are there

Anybody ?
 
Vanni75

As FCG suggested your a suffering from grid reconstruction, take a look at faq184-1813.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Vanni75,

select tablename
set key to 'Agents'

nRec = RECNO()
GO nRec
or
LOCATE or GO TOP or GO BOTTOM or some such record pointer movement or positioning is required for successful setting of the index. The current record position will take its effect often, but for a guaranteed effect, you have to move the pointer. That will solve your problem. :)



ramani :)
(Subramanian.G)
 
Hi,

thx for trying to help me, but all the answers aren't teh correct one. I still have a empty grid. The only thing that helps is totally reconstruct teh grid even the tip from
"As FCG suggested your a suffering from grid reconstruction, take a look at FAQ184-1813. " didn't help.


But thx anyway.. I hope someone still comes with a solution ;-)
 
vanni75,

Here's an example I just worked up. It uses command buttons to Set Key To and shows changes in the grid. Could you tell me if it works for you? If there are some differences between it and what you are trying to do that would make a difference please explain. Cut-N-Paste the code below into a prg file and run it from within VFP.

PUBLIC oForm

oForm= CREATEOBJECT('clssetkey')

oForm.ADDOBJECT('Grid1','Grid')

WITH oForm.Grid1
.COLUMNCOUNT = 4
.HEIGHT = 288
.PANEL = 1
.WIDTH = 440
.LEFT = 24
.TOP = 24
.Column1.WIDTH = 100
.Column1.NAME = "Column1"
.Column1.Header1.CAPTION = "GROUP"
.Column2.WIDTH = 100
.Column2.NAME = "Column2"
.Column2.Header1.CAPTION = "FIRST NAME"
.Column3.WIDTH = 100
.Column3.NAME = "Column3"
.Column3.Header1.CAPTION = "LAST NAME"
.Column4.WIDTH = 100
.Column4.NAME = "Column4"
.Column4.Header1.CAPTION = "PHONE"
.Column4.Text1.FORMAT = "KR"
.Column4.Text1.INPUTMASK = "(###)###-####"
.Column4.sparse = .f.
.VISIBLE = .T.
ENDWITH

oForm.VISIBLE = .T.

DEFINE CLASS clssetkey AS FORM

TOP = 0
LEFT = 0
HEIGHT = 334
WIDTH = 600
DOCREATE = .T.
CAPTION = "SET KEY DEMONSTRATION"
WINDOWTYPE = 1
WINDOWSTATE = 0
NAME = "clsmultigrid"

ADD OBJECT cmdAgents AS commandbutton WITH ;
Top = 24, ;
Left = 470, ;
Height = 27, ;
Width = 110, ;
Caption = "Agents", ;
Name = "cmdAgents"

ADD OBJECT cmdScientists AS commandbutton WITH ;
Top = 75, ;
Left = 470, ;
Height = 27, ;
Width = 110, ;
Caption = "Scientists", ;
Name = "cmdScientists"

ADD OBJECT cmdNonExist AS commandbutton WITH ;
Top = 125, ;
Left = 470, ;
Height = 27, ;
Width = 110, ;
Caption = "Non-Existant", ;
Name = "cmdNonExist"

ADD OBJECT cmdAll AS commandbutton WITH ;
Top = 175, ;
Left = 470, ;
Height = 27, ;
Width = 110, ;
Caption = "Restore All", ;
Name = "cmdAll"

PROCEDURE LOAD
CREATE CURSOR crsTemp (grouping c(25), firstname c(25), lastname c(25), thephone c(10))
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Agents", "JOHN", "SMITH", "1111111111")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Scientists", "AMY", "SUTTON", "2222222222")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Agents", "BILL", "BRADLEY", "3333333333")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Scientists", "LUCY", "LUI", "4444444444")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Agents", "CHUCK", "NORRIS", "5555555555")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Scientists", "BRUCE", "LEE", "6666666666")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Scientists", "KATHERINE", "HEPBURN", "7777777777")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Agents", "JIM", "WALKER", "8888888888")
INSERT INTO crsTemp (grouping, firstname, lastname, thephone) ;
VALUES ("Agents", "SANDY", "LITTLETON", "9999999999")

INDEX ON grouping TAG grouping

GO TOP IN "crsTemp"
ENDPROC

PROCEDURE cmdAgents.click
SET KEY TO "Agents"
LOCATE && Only makes sure we are not at the bottom of the grid
thisform.grid1.refresh()
ENDPROC

PROCEDURE cmdScientists.click
SET KEY TO "Scientists"
LOCATE && Only makes sure we are not at the bottom of the grid
thisform.grid1.refresh()
ENDPROC

PROCEDURE cmdNonExist.click
SET KEY TO "Presidents" && Nobody has this
LOCATE && Only makes sure we are not at the bottom of the grid
thisform.grid1.refresh()
ENDPROC

PROCEDURE cmdAll.click
SET KEY TO
LOCATE && Only makes sure we are not at the bottom of the grid
thisform.grid1.refresh()
ENDPROC

ENDDEFINE


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
An additional note for you vanni75...

If you end up with a blank grid and the records are actually there you should try:

[ol][li]set focus to the grid and refresh it

[/li][li]Goto the top of the grid's recordsource, then refresh the grid[/li][/ol]

...if it still doesn't show anything then it is most likely that:

[ol][li]you're not looking at the actual data source for grid

[/li][li]the data source is indeed empty

[/li][li]you have yanked the grid's data source out from under it (Grid Reconstruction as mentioned by Mike)[/li][/ol]


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top