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!

to populate data editable data grid view based on text box

Status
Not open for further replies.

alazarbaharu

Instructor
Apr 17, 2015
11
GB
hello guys i have the following problem in developing a database application with VFP
and here is the explanation to my problem

i have table called residency

having three atributes

locationid

individualid

educationalststfirst

and data is already entered on it but always the educational status needs to be update. i have a form and on that form there will be a textbox where user will input the location id so that every individual from that location will be populated on the data grid view then a user can modify the educational status of the individuals from the grid view and the data will be saved to the residency table permanently. please i need your help on this badly. i have already tried this using cursor read write privilege but the data will not be updated permanently!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thank you.
 
To update the data you need either
1. Bind the table itself and only use SET FILTER on it
2. Bind an updatable View or Cursoradapter

Readwrite does not mean the same as updatable, you only change the cursor.

You could now also write an update statement updating the table from the modified cursor, as you are that far. But binding the table itself seems the simplest approach for you small case.

Bye, Olaf.
 
What is the RecordSource of the grid? Is it a cursor, or is it the underlying table?

From what you have said, it sounds like you are using a cursor, containing just those records that have the specified location ID. If that's right, then any edits in the grid will update the cursor, not the underlying table. The solution is either: use the underlying table as the RecordSource, and use SET FILTER to show only the records you are interested in; or, after updating the cursor, copy the edited data from the cursor into the table (perhaps using UPDATE ... FROM).

If you are already using the table as the RecordSource, is it buffered? If so, you need to do a TABLEUPDATE() to commit the changes.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hello OlafDoschke can i do this

on the form i have textbox txtloc
and i have a grid called grdresidency
i have droped one command button on the form and on the click event of the button i have putted this code

set filter on locationid=thisfrom.txtloc.value
thisform.grdresidency.refresh
thisform.grdresidency.setfocus

then based on the inputted location id every individual living in that location will be populated to the gridview then i can modify the educational status of this individuals. i tried this but it is not working as i expected. so pleace help me on the idea of doing this with set filter.thank you.
 
First, you need to say SET FILTER TO, not SET FILTER ON.

But you have also not answered our points about the RecordSource, and which work area is selected at the time you run the command button code.

Assuming the RecordSource is indeed the Residency table, I suggest that, as a minimum, you [tt]SELECT Residency[/tt] immediately before you set the filter, and also you include the alias in the filter condition, like so: [tt]SET FILTER TO residency.locationid = thisfrom.txtloc.value[/tt].

Also, if LocationID is a character field, I would apply ALLTRIM() and UPPER() to the filter:

[tt]SET FILTER TO ALLTRIM(UPPPER(residency.LocationID)) = ALLTRIM(UPPER(thisfrom.txtloc.value))[/tt]

Finally, if that doesn't solve the problem, please tell exactly what is going wrong. What behaviour are you seeing? Are you seeing an error message, or what? To simply say that it doesn't work is not helping us.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
hello Mike thanks for your help and finally it worked for me and just to answer your questions the recordsource is the residency table and finally is working form me. and let me ask one more question how can i get a textbox value in form one to form two.
Thank You...
 
I don't if you come from Access or where you come from, but in foxpro you don't easily address another form than THISFORM. You'd have to have a variable for the other form so you could do loOtherform.txtLoc.Value = Thisform.txtLoc.Value.

There are other ways to transport data between forms, better ways, more to the point ways. You bind controls to data, then changing data also influences other forms binding to the same data. That is a general and preferrable principle instead of "peer to peer" comuncation between forms.

Bye, Olaf.

 
In regard to setting the filter, though it works, you could get into trouble, if the form loses focus. Then "THISFORM" is not valid anymore, but is still referred to in the filter definition.

So don't...

[pre]SET FILTER TO ALLTRIM(UPPPER(residency.LocationID)) = ALLTRIM(UPPER(thisform.txtloc.value))[/pre]

..., instead do this:

Code:
Local lcLocationEntered, lcFilterCondition
lcLocationEntered = ALLTRIM(UPPER(thisform.txtloc.value))
lcFilterCondition = Textmerge("ALLTRIM(UPPER(LocationID)) = '<<lcLocationEntered>>'")
* for debugging purposes display the computed filter condition:
MessageBox("Filtering with this condition:"+lcFiltercondition) && remove after debugging
SET FILTER TO &lcFilterCondition IN residency

This way the filter isn't interactively reacting to changes of the textbox value anymore, but also isn't depending on the form being the activated form. You have to understand a filter isn't part of the form, it's set in the workarea "residency", so it should only address fields from that table and literals (strings, numbers). the filter condition should not address objects, variables or other things with a different scope than the workarea, if you do that, that's just like asking for trouble and if you get an error later you'll not know where it comes from, as the filter condition is checked, erros, but your error handler will not tell you a program or line number to debug. The error will seem to come from thin air.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top