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

How to prevent refresh of a control when you do thisform.refresh

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi all,

In my form, there is are 2 grids and 2 edit boxes. Let's say Grd1, Grd2, Edt1, Edt2. All controls are ReadOnly except for Edt2.
Grids shows records from 2 tables and both the Edit boxes are for Memo fields.

At any given time, the user may be editing content of Edt2 and other controls being updated by a timer. In the timer, I have given <control>.Refresh for all except for Edt2 because the user could be still editing it.

But, now the problem is for some reason, my Edt1 is not being shown updated even when my Grids are updating.
I observed that, if I use thisform.refresh, then it gets refreshed. But, I cannot use this because then it refreshes Edt2 as well and its contents vanish (as control is still inside it and the value not written to disk) and cursor goes to top of edit box. This is obviously by design, isn't it ?

So, is there any way to avoid the refresh of a control when we do thisform.refresh

Any idea?

Rajesh
 
Code:
Try
   If Thisform.Activecontrol.Name == "Edit2"
      Thisform.Activecontrol.SetFocus() && setting focus to the active control causes the chain of all events that include saving current value. 
   Endif
Catch && in case Thisform.Activecontrol is no object, that means
   * no control has focus = no problem
Finally 
   Query tempcursor data here and refresh grid, etc.
   Thisform.Refresh()
EndTry

See comments. This will first save edit2, then fetch updated data, update cursors, and refresh controls.

Edit: Ensure nothing blocks Edit2.valid when you set focus to it. Also, ideally you'd not do anything when data is unchanged. The Problem is you only know when you already did the major job of fetching data again. All you could spare is Thisform.Refresh. A sensible timer interval should prevent this from taking too much time, besides lowering the network load of unnecessary queries.

Chriss.
 
Hi Chriss & All,

Okay, I can check your suggestion but I think, I missed few of important points, sorry!

The controls, other than Edt2, are being modified by other users (from another form) and the latest data to be shown in this form.
Edt2 is being modified by this user.

The idea is, this user should see the latest content updated by other users (data of Grd1, Grd2 & Edt1) while he is modifying Edt2 time to time.
However, while I need refresh for Grd1, Grd2 & Edt1, I don't want to refresh the Edt2 only because the user will be inside that editing it and a refresh will disturb it and possibly removing the content that he is currently entering.

Rajesh




 
You missed the comment in the code:

Setting focus to the active control causes the chain of all events that include saving current value.

Chriss
 
Is it perhaps, that Edit2 is only bound to one of the cursors and you overwrite that anyway?

Well, then you mainly have two choices: 1. Don't bind the edit2 box, just store the initially loaded value and finally store its last value back, no matter how often you'd call Refresh. (That's perhaps the simplest).

2. Keep the value of Edit2, including SelStart, before you requery data. And then replace that memo in tempcursor before it replaces the form cursor data by either ZAP/APPEND or what I showed you could do instead in your other current thread.

You could also check, whether the value you load differs from original and current value, which should be addressed.

Chriss
 
Hi Chriss,

This is solved mostly. Just to explain the scenarios once again.

1. Grid1, Grid2, EditBox1. The data is in Table1. These are continously modified by other users and the latest data to be shown in this form, time to time.
2. EditBox2. The data is in Table2. This is continously modified by this user and should be saved only when user confirms it by clicking a button 'Submit'.
3. There is a relation from Table1 to Table2 on field DOC_ID.

4. I am using a timer to do the time to time data refresh of Grid1, Grid2, EditBox1.
5. However, in timer, I am not using THISFORM.REFRESH because I don't want to disturb the entry happening on EditBox2.
Chriss had suggested here to use SetFocus() to EditBox which will force saving of data. But actually, I don't want to save data untill the user confirms it.
I had forgotten to mention this earlier :-(.

Now, in the Timer event, I added a 'GO (RECNO()) IN TABLE1' and I am getting the latest values in Grid1, Grid2, EditBox1.
Also, data entry in the EditBox2 is not at all disturbed even when the timer does its job.

So, this mostly seems to be solved.
However, I need to check for side effects on a multi user scenario because I am not using Buffering in both tables (in order to make the record update straight & immediate.

Thanks to all,
Rajesh
 
Rajesh said:
I don't want to save data untill the user confirms it.

Then you could:
1. create the temp cursor of Table2 (with the Editbox2 record)
2. For the currently edited record Replace the data with EditBox2 value
3. ZAP and APPEND (or use the other recmmended data refresh), then a Thisform.REfresh() becomes possible.
4. To not even shift the cursor, also store and restore the SelStart and SelLength of the Editbox.

Or simpler, don't bind Editbox2, neiter to Table2 nor to a crsEditBox or whatever. It's not affected by a Refresh(), then.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top