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

Not allow changes in a grid 1

Status
Not open for further replies.

coldan

Programmer
Oct 19, 2008
98
AU
I have a simple grid on a form. I want to allow changes to the data fields when the 'Edit' option is chosen on a 'selections' form via a checkbox.

I am using mode as the variable name which I pass to the form.

What property can I change in the init of the form to prevent or allow changes? Is this a 'read only' statement somewhere?

When editing is allowed does a change to text in a row mean that the new values will be automatically saved to the underlying table.

If not, I propose adding a [Save] button on the form.

What code should I have in the click event of the Save button?

Many thanks

Coldan
 
We need more information to be able to answer your question.
Do you want to edit fields directly in grid or in separate controls on the form? Do you use buffering with your table?

PluralSight Learning Library
 
Hi Coldan,

You can set the grid's ReadOnly property to determine whether or not the user can edit the cells.

Also, when ReadOnly is .T., it's a good idea to set AllowCellSelection to .F. This will prevent the blinking cursor appearing in the cells.

If the underlying table or cursor is not buffered (which is the default), then any edits the user makes will be committed as soon as the user moves the highlight to another row (or closes the form).

If you prefer to have a Save button, you should put the underlying table into a table buffering mode (see the Help on buffering for details). You will also need an Edit and a Cancel button.

Now, start out with the grid in ReadOnly mode. In the click of the Edit button, change ReadOnly to .F. (and AllowCellSelection to .T.). In the Save, do a TABLEUPDATE(), which will commit the edits. In the Cancel, do a TABLEREVERT(), which will cancel the edits. In both the Save and the Cancel, put ReadOnly back to .T. and AllowCellSelection to .F.

This should get you started. Come back if you have any more questions.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I'm not sure I agree with your ideas here for a couple of reasons:

- According Windows UI Guidelines, a checkbox should not initiate an action. In this case, it is initiating Edit. A CommandButton would be a better control.

- You don't say, but I assume you want to put the grid into Edit mode. A grid is not a good editing control. It's too difficult to add validation, etc. I allow the user to double-click the row or click and Edit button that pops up a modal child form for editing the same fields contained in the grid.



Craig Berntson
MCSD, Visual FoxPro MVP,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top