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

Need to fire an event twice to get the expected result

Status
Not open for further replies.

SimplyES

Programmer
Oct 5, 2012
39
GB
I have a form with a grid and a 5-page pageframe. The grid lists patient names and the pageframe displays data for each patient. [AllowCellSelection] is set .F. and clicking on the row for any particular patient updates the rest of the form appropriately. As part of the updating process, The [Click] event on the grid runs a few methods, one of which is composed to update a series of 10 checkboxes. The code in the method is fine but, although the rest of the data updates, the checkboxes don't update, as though that one method isn't firing. If I click a second time (not [DoubleClick]) then the checkboxes are updated. As part of trying to diagnose this I used Debug, of course, but that didn't help because the routine worked perfectly when working through it stepwise! I should say that the very first time the grid is clicked, when the form is first opened, the correct result occurs .. .. just that once. I have not experienced this in any other project to date.

I have finally found a workable resolution which is satisfactory for keeping the project going. It doesn't tell me why the [Click] event is not responding as normal and I would be grateful if anyone has the answer.

My fix was to place a [SetFocus] right at the end of the method to switch focus to another object on the form (I elected the close button). It seems that clicking the grid row 'from outside' the grid persuades the [Click] event to behave properly (that's why it worked with Debug, of course, and why it works when the form is first opened).
 
Grids can mess with you.

Among other things, clicking on a grid immediately SELECTs the alias that's driving the grid. If you have any responding code that expects something different to be currently SELECTed (which you shouldn't do, of course), you may be in for a surprise.

Are the misbehaving checkboxes bound?
 
You should use the afterrowcolchange event in grids. The grid click only is triggered, if you click on grid border/lines. Clicking on cells triggers the click of the textbox controls (or whatever control is used in a grid cell, and not the grid click.

Bye, Olaf.
 
Olaf has given you the right answer.

But, in general, your workaround of doing a SetFocus is also correct. Whenever you make any change to the values within a gird, or when you change the record pointer of the underlying table, it is good practice to set focus back to the grid, to ensure that the changes become visible.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
AfterRowColChange is not one I have bumped into until now. Thanks for that. I've read up on it now and that's what I will use instead in future. However, the problem was still there after I moved the code over.

The checkboxs' control source is fields (vars) in an array. The failing method, which is fired from AfterRowColChange (now!), refills the array. There is one other method in the list before this one with three SQL Selects.

Mike - for the record, my 'miracle' SETFOCUS was moving the attention off the grid! However .. .. ..

I now have two change options that both work.
1) added a SELECT <Alias> back to the original table (the one under the grid) just before the method which was failing.
2) without the above change, but in the same place, added in SETFOCUS to the grid

Of course, they acheive the same thing as far as my failing method is concerned but I am going for the SETFOCUS option because that means I'm not leaving the focus somewhere where I don't want it.


Gents - thanks. Speed of response is most impressive. I should have signed up here months ago.
 
Well, the other magic codeyou search for simply is THISFORM.Refresh(). Refreshing variables, arrays, also cursors or tables doesn't refresh what is displayed.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top