Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Textbox in grid column.... When is cursor updated?
Message
From
26/09/2017 08:55:19
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
25/09/2017 14:11:08
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01654540
Message ID:
01654571
Views:
65
>>Textbox in grid column question.... When is the value entered in a textbox in a grid column applied to the underlying bound cursor relative to the firing of the grid.AfterRowColChange() when user hits tab to move to the next column?
>>
>>Here is the situation I am struggling to understand: When entering a new value in a column and then hitting tab to go to the next column, it appears that the value from the textbox which you are exiting is not applied to the cursor yet at the time AfterRowColChange() fires. I have some calculation logic on AfterRowColChange() and the old value is what I am seeing.
>>
>>As a hack, I have gone this route, but I hate it: In order to get the value from the textbox in the cursor soon enough to be seen by the AfterRowColChange() method code, I have put explicit code in the textbox.Valid() to say “Replace {field} with This.Value in {lcCursor}” and then the cursor is updated so that when AfterRowColChange() is called, it will see the new value in the row for that field.
>>
>>
>>** UPDATE **
>>
>>I have confirmed that if I use the down arrow to exit the textbox and move to the next *row* in the grid, the calculations in AfterRowColChange() work perfectly, so that shows that the value from the textbox is applied to the cursor beforehand when changing rows. But, when moving horizontally from one column to another, I have to move *2* columns before the calculations based on the underlying cursor work properly.
>>
>>.
>
>I have a rule when working within grids: Never reference another grid column by object name, instead reference the cursor's column name (field name).
>
>Supposing I have a form with a grid with two columns, each column with its respective textbox, and the grid's RecordSource = 'GridCursor', I would write the following code in the Valid() method of the textbox of the first column:
>
>
>
>LOCAL lcId
>lcId= This.Value
>IF SEEK(lcId, 'LookupCursor')
>   REPLACE GridCursor.Field2 WITH LookupCursor.Field3
>ELSE
>   REPLACE GridCursor.Field2 WITH ''
>ENDIF
>
>
>I hope this helps you.

That should be REPLACE Field2 with LookupCursor.Field3 IN GridCursor.

While REPLACE CursorName.FieldName with value works, that is not the intended purpose. The reason to use CursorName was for updating fields in DIFFERENT aliases during a replace with a SET RELATION. It became a too common habit, but is not necessary. It increases the amount of typing without preventing the problem solved by the IN clause.

**UPDATE** Seeing your response to Boris, if you're certain you're in the right alias, then you don't need to prefix the field name with the cursor at all. So, recognize this as old habit.
Previous
Reply
Map
View

Click here to load this message in the networking platform