Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug: GetFldState() and Grids?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00058853
Message ID:
00058913
Views:
31
>I've been tracking a bug in an application where data is not being saved from a grid properly. I have found the following problem: When you issue GetFldState(-1) from a grid, in the down-arrow keypress for example, unless you have moved your cursor off the column you modified and onto another column, GetFldState will not see your changes.
>
>So, say you have a grid with two columns. The first column is a C(1) field and the second is a C(10) field. Now, if you are on the first column of the grid and change the field (since it is a one character field, you will now be on the second column) GetFldState(-) will return "21", which is correct. If you are on the second column, however, and enter a few characters (it doesn't matter, as long as it is less than the 10 char size of the field) GetFldState(-1) will return "11" which is incorrect.
>
>Does anyone have suggestions on a fix for this rather annoying bug?
Michael,

First off this is NOT a bug, it is by design. The design is that when a control fires its Valid event it then updates its controlsource. If you check GetFldState() before the control's valid has fired then the underlying controlsource ahs not yet been updated by the control and so you have no change to the field.

The solution to this is to call the setfocus of the current control before you check GetFldState(). This forces the current control to first lose focus and then regain it thus firing the control's valid and updating the controlsource with teh value of the control. This will cause the GetFldState() to see that the underlying contorlsource has changed and report that change to you.

IOW, in your keypress event you would do something like this (assuming that it is the form's keypress that you are using)

THISFORM.ActiveControl.SetFocus()
lcFldState = GetFldState(-1)
* Now whatever you want to do with the result
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform