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

Grid - before rowcolchange

Status
Not open for further replies.

Kurjo

Programmer
May 13, 2003
67
US
Hi,

I would like to get some expert opinion on this matter.

I have a grid on a form. I want to control the data changes on the grid. What I did is that in beforerowcolumnchange event I put some code to check the validty of the data (I need to check it only the user changes the row so I took the changevalue 2 or 3 to proceed). If any validity rule is broken I want the cursor come back to the same row.

My question is that should I use the underlying table fields to check the validity or thisform.grid1.column1.text1.value ?

How do I come back to the same row ? where do I have to put that code to comeback ? Is it in afterrowcolumnchange ?

Any help is appreciated.

Kurjo
 
Kurjo,

I would put my validity check in the Valid event of the textbox (within the column within the grid). Use the textbox's Value property to access the contents of the control. If your validity test fails, just return .F. -- that will endure focus stays in the cell. If it doesn't fail, return .T.

Mike


Mike Lewis
Edinburgh, Scotland
 
Thanks Mike for the response. I would like to do what you told. I have six columns in the grid need to be validated. My Boss don't want the user to get error validity message for each and every column. He want to display a combined message when the user changes row.

 
Hi

If you are using VFP8, you have a facility. A new property
Grid.RowColChange is available.

IF Grid.RowColChange = 1 it means row change
Grid.RowColChange = 2 it means Column change
Grid.RowColChange = 3 it means change in Both
Grid.RowColChange = 0 NO change.

If you are using earlier version, you can do the same in your intutive way. Creat a property nRec in your Grid class or in your form. Then in the AfterRowColChange event, put the code..
IF RECNO() = nRec
** Only Column Change.. so dont do validation yet
ELSE
** DO VALIDATION now
IF ! Success
** give validation error message
NODEFAULT
ENDIF
ENDIF
ThisForm.nRec = RecNo()

:)

ramani :)
(Subramanian.G)
 
Ramani,

That is a good idea. One thing I would like to know when I validate the values, should I use table fields or grid1.column1.text1.value?

In my test I saw when the user dont press enter some times the table field do not get updated (when they use arrow keys to move up or down).


 
Hi

It is advisable to validate all the grids data just before doing the update to the table. There are many ways to leave a grid or a row or a column and we can fail to trigger the validation. SO in the save buttons code, we have to validate and return the user to the relevant text box or grid row.

However, timely validation can be executed as a supplement from within grids rowcolchange event.

:)

ramani :)
(Subramanian.G)
 
Thanks folks.

I have validation routine in the save button. But this grid level validation is a supplement to that. If we can pop up some message as soon as the user change the row it is less tedious to fix all the errors at the end when the user hits the save button.

I found Grid.RowColChange is avilable in VFP 7. I am using VFP7.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top