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!

HOW CAN I REPON A GRID THAT ALIAS DBF WAS CLOSE AND REOPEN

Status
Not open for further replies.

farzad321

Programmer
Sep 14, 2019
53
FR
HI TO EVERY ONE.
I HAVE FORM AND A GRID ON THAT . I NEED TO WHEN FORM IS OPEN , CLOSE DBF ALIAS OF GRID AND REOPEN IT WITH SELECT COMMAND. BUT WHEN TABLE WAS CLOSED AND CREATE AGAIN, THE GRID WAS CLEARED AND NEVER SHOW THE CONTENT OF NEW TABLE AGAIN. HOW CAN I REPAINT OR REOPEN THAT GRID AND USER CAN ACCESS TO GRID DATA?
 
Before you run the SELECT command, set the grid's RecordSource to an empty string. Then do the SELECT. Then set the RecordSource to the alias of the cursor produced by the SELECT.

You don't need to explicitly close the DBF.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
THANK YOU MIKE
I AM WORKING IN FORM DESIGNER USUALLY AND WHEN ADD GRID TO FORM, [highlight #FCE94F]IN PROPERTIES OF EVERY COLUMNS[/highlight] WRITE THE FIELD NAME (AND COLOR AND FONT AND WIDTH AND SO ON) OF MY TABLE AND [highlight #FCE94F]I DO NOT WRITE ANY COD FOR MY GRID[/highlight]. AT SOME TIMES I NEED TO CLOSE DATA TABLE WHEN FORM AND GRID IS ACTIVE (WITH ANY REASON). HOW CAN I REFRESH MY GRID WITH LAST CONFIGURATION IN FORM DESIGNER?

SELE 0
USE MTABLE
ACTIVATING FORM
ACTIVATING GRID IN IT
WHEN USER PRESS X PUSH BOTTOM I MOST CLOSE TABLE AND RE-CREATE IT
[highlight #EDD400]IN THIS TIME GRID WAS CLEARED AND DOES NOT SHOW ANYTHINGS[/highlight]
THEREFOR MY FORM IS USELESS AFTER PRESSING POSH BOTTOM


Capture_ovpji5.jpg
 
Unless you're allowing the user to edit in the grid, the best thing to do is to put the data in a cursor (by using SQL SELECT) and use the cursor as the grid's RecordSource. Then, if you need to close the original table for some reason, the grid will be unaffected.

If the issue is that the table might get changed in some way from somewhere else and you want the grid to show those changes, then you want to use the technique generally called "Safe Select." To do that, you create a cursor (probably in the form's Load event) with the columns you need. Then, to fill it, you using code that issues the SELECT into a different cursor and then ZAPs and copies into the one for the grid. Here's more information on that technique:
Tamar
 
hi tamar

thank you for your help and sorry for delay of my answer
I will do your technique and test the result. I hope solve my problem.

I think my weakness is when i create a form and grid on it , firstly [highlight #FCE94F]use a master table for source of grid and i can not zap or delete it[/highlight] and this is mistake , and second i do all setup of grid in properties and NOT source code. therefore when I need to close and reopen the table, my grid column field name and color and font and header and ... will be lost.

with best regards
 
It's fine to set up your grid in the property sheet, but to do so, you should use a cursor and the safe select technique I suggested.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top