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

There is a local view, the grid on 1

Status
Not open for further replies.

sashaDG

Programmer
Jun 20, 2022
112
BY
There is a local view, the grid on which the view is displayed, also have CURSORSETPROP('Buffering', 5, 'myview') and others settngs fields of view.

Please help: how to add a button for editing rows, a button for adding an empty row for further inserting data and a button for saving data in the view(TABLEUPDATE() i should use).
 
For editing a row, you don't need to do anything. The user can just click in the grid and start editing (assuming the grid is not read-only).

For adding a row, you can do [tt]APPEND BLANK IN <view's work area>[/tt] in the button's Click event. The new row will then be available for editing. (You might need to set focus to the grid to make the row visible.)

To save the edits, do [tt]TABLEUPDATE()[/tt] in the Click event of the Save button. You should also have a Cancel button which has [tt]TABLEREVERT()[/tt] in the Click event.

Now having said all that, I have to say that editing data in a grid makes for a poor user interface. It is better to use the grid for navigating the data rather than directly editing it. A better approach is to let the user double-click on the row they wish to edit; that would open a modal form which contains all the data-entry fields for the view; when they save and close the form, the view gets updated.

Alternatively, place the data-entry fields on the same form as the grid. As the user navigates the grid, refresh the data-entry fields so that they always show the data for the current row. Let the user edit those fields, rather than the grid. You would still need Save and Cancel buttons, as above.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sasha,

Mike has several excellent suggestions. As an additional minor option, you could set the grid's AllowAddNew property to .T. You can then add a blank row with the down arrow when on the last record.

As another approach, I like to use a List instead of a grid. As Mike indicated, the data-entry fields would be on the same form and show the data automatically for the list item clicked. You would need to set the ControlSource for each textbox (or OptionButton) to the corresponding field. I normally do that in the Init().

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top