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

Can you edit grid?

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
590
PH
I have a grid that displays record, can you delete a row or edit data from the grid? May i ask how? thanks...
 
Hi Mandy,

The short answer is Yes.

If you want to delete or edit a row from within your program, what you must do is to delete or edit the corresponding record in the underlying cursor or table. Remember, the grid is just a view of your table. Whatever changes you make in the table will be reflected in the grid. (You would usually need to either set focus on the grid or refresh it in order for the change to become visible.)

If you want to allow your user to delete or edit the grid interactively, that's posssible as well. In fact, a grid is editable by default. You don't need to take any special action to let the user click on a cell and edit it. To delete a record, they click on the narrow column at the extremem left edge of the grid.

Just to add: if you want to prevent the user from editing the grid, you should set its ReadOnly property to .T. You can also do that for individual columns in the grid. If you want to allow editing but prevent deletion, set the grid's DeleteMark property to .F.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mandy,

In addition to Mike's post: you'll have to make sure that the grid's RECORDSOURCE is a Table. If it's a view or a cursor, things become more complicated and you'll have to "transfer" the changes to the underlying table(s)

hth

MarK

 
Mark, you're right about it being a cursor. I hadn't thought of that. But I think a view is different. Provided the settings are right, a grid can update a view which can in turn update the underlying table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike

[highlight #FCAF3E]Provided the settings are right[/highlight], a grid can update a view which can in turn update the underlying table.

You're right. But

Views are, by default, buffered with optimistic row buffering. You can change this to table buffering; for more information on buffering, see Chapter 17, Programming for Shared Access.

from VisualFoxPro 6 - Programmers Guide by Microsoft

Hence you have to TABLEUPDATE() them - perhaps in AFTERROWCOLCHANGE() or in LOSTFOCUS() of the grid - and only then the changes will be send to the underlying table(s) - depending on their buffer settings they have also to be TABLEUPDATEd().

p.s. I nowhere found a hint that a view buffering could be set to 1 (NO buffering)

MarK
 
Hi Mike,

With row buffering, as the user navigates the grid, any changes are sent to the table.

That's true up to the last row. You'll either have to move up one row or call TABLEUPDATE() when leaving the grid. And I know from my experience that it is almost impossible to make a user move up one row when having reached the last one, usually moaning "Why is it not saved?"

MarK
 
In addition to the points made by Mike (Yearwood) and Mark, when I talked about a view being able to update a table "provided the settings are right", I was thinking of the settings on the Update Criteria tab of the view designer, or their equivalents in CURSORSETPROP(). Things like WhereType, SendUpdates, UpdatableFieldList and UpdateNameList.

But to go back to the original questionm, the easiest way to edit a grid is to edit the underlying table.

Mandy, we haven't heard back from you since you started this thread. Were our answers any use to you?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike, mark yearwood and everyone... thank you for all your answers... im still studying all your inputs so that i could use it to my project and to my future projects... thanks and God bless...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top