Johnvrmln123
Programmer
Hello to all,
The following code creates a form on a grid. To validate changes in the grid i use the BRCC method an nodefault to ensure that no row change will take place when the record could not be validated.
In this example code the validation should never succeed because it is set to false. (In my main program this would be the outcome of a validation function for instance.)
When another row in the visible part of the grid is selected nodefault prevents de row from being changed. This is ok. But when the grid is scrolled an then the mouse is used to select another row the first visible row in the grid is selected! This is not ok because nodefault should prevent row change. I found that this behavior is caused by the refresh-event that is enterd in the BRCC-event.
Does anyone know why this behavior occurs? and how I can make sure the row is not changed when nodefault is used, without having to offer the refresh?
My code (VFP9, SP2):
Thanks in advance.
John Vermeulen
The following code creates a form on a grid. To validate changes in the grid i use the BRCC method an nodefault to ensure that no row change will take place when the record could not be validated.
In this example code the validation should never succeed because it is set to false. (In my main program this would be the outcome of a validation function for instance.)
When another row in the visible part of the grid is selected nodefault prevents de row from being changed. This is ok. But when the grid is scrolled an then the mouse is used to select another row the first visible row in the grid is selected! This is not ok because nodefault should prevent row change. I found that this behavior is caused by the refresh-event that is enterd in the BRCC-event.
Does anyone know why this behavior occurs? and how I can make sure the row is not changed when nodefault is used, without having to offer the refresh?
My code (VFP9, SP2):
Code:
PUBLIC frm
frm = CreateObject ("myForm")
frm.Visible = .T.
DEFINE CLASS myForm As Form
Width = 400
Height = 350
AutoCenter = .T.
* Add a grid to the form
Add Object Grid1 as Grid with;
RecordSource = "MyCursor", ColumnCount=1, Visible=.t., Top=20, Left=20, Width=360
* Add cancelbutton to the form
ADD OBJECT cmd As CommandButton WITH;
Width=60, Height=30, Left=20, Top=250, Caption="Cancel"
* Provide validation before row is changed
PROCEDURE Grid1.BeforeRowColChange
LPARAMETERS nColIndex
if inlist(this.RowColChange, 1, 3) && if row changes
loValidate = .f.
if not loValidate && some validation, in this case always false
* message ...
* set the value off some controls
nodefault && in this example the user should not be able to change the row in the grid
thisform.refresh && to refresh some controls on the form
endif
endif
* Create a release button
PROCEDURE cmd.Click
ThisForm.Release
* Create a cursor wiht 100 names
PROCEDURE Load
Create Cursor MyCursor (Name Character(20))
For x = 1 to 100
Append Blank
Replace name with "name" + Alltrim(str(x))
Next x
Go Top
ENDDEFINE
Thanks in advance.
John Vermeulen