Edit Form Refresh on new selection

533
3
10-08-2012 11:55 AM
KeithGanzenmuller
Occasional Contributor II
Not sure exactly how to phrase it, that's as close as I could come.

Have a curious problem that I am sure one of you can help me with.

Have an axf with a single layer of points with meter locations, the axf contains an EDITFORM.
I have the user select a meter point on the map and code to show the EDITFORM using the OnSelectionChanged  and the featureproperties internal command. Works fine. All the field attributes show up correctly.

We have 2 custom buttons Next and Back which select the next or previous meter in the sequence for editing based on its sequence number. The sequence numbers are not necessarily in the same order as the record numbers.
What I want to happen is the data on the form for the current feature to be saved and the data for the newly selected feature to be displayed for editing.

I have code which correctly finds the next meter and selects it. The meter shows selected (highlighted) on the map and the OnSelectionChanged event fires which I test with a msgbox.
What I can't get to happen is the data on the form to change to the new feature.
I've tried closing the EDITFORM then clearing selection then reselecting, which I can do, but I can't get the EDITFORM to redisplay without manually clicking the featureproperties button. Even using the internal featureproperties command doesn't work the second time.

Any ideas?

Thanks, Keith
Tags (3)
0 Kudos
3 Replies
KeithGanzenmuller
Occasional Contributor II
My suspicion is that the open EDITFORM is not completely unloaded and still shows mode = 2 (Editing an existing feature ).

One work around that shows some promise (although perhaps not the most elegant) is to enable the TIMER and check for the EDITFORMS state being back to -1 (Not currently open ).

I have confirmed it does work but haven't worked out all the details of saving the current data before closing the form.
If there is a better way I am open to it, as I think this is perhaps not the best way.
0 Kudos
ThaiTruong
Occasional Contributor II
Keith,

Have you tried to use RecordSet::Update to save changes to your current record?

Under OnClick event of your Next & Back buttons, you need to save the current record before create a new query and select a next/previous record.

For the second issue, you wish there's a refresh method for the edit form, don't you?! 🙂
Since your OnSelectionChanged event fired up, I think you can write code to update your form's controls with the new selected record under this event.
0 Kudos
SuzanneAngelo
New Contributor II
I had a similar problem; the EditForm had mode=2 and would not reopen.  This solution worked for me.

My suspicion is that the open EDITFORM is not completely unloaded and still shows mode = 2 (Editing an existing feature ).

One work around that shows some promise (although perhaps not the most elegant) is to enable the TIMER and check for the EDITFORMS state being back to -1 (Not currently open ).

I have confirmed it does work but haven't worked out all the details of saving the current data before closing the form.
If there is a better way I am open to it, as I think this is perhaps not the best way.


My case was slightly different in that I wanted to open the EditForm from a secondary form in the Layer's .apl file. (I have a shapefile instead of an AXF).   It was very annoying that the EditForm appeared to my eyes to be closed already; only that other form was visibly open.  And still Layer.Forms("EditForm").Mode=2.  (Sigh...)  Here is how I implemented kganz's solution...

In the Layer's .vbs code, I added the following lines after selecting the next feature to be edited (the EditForm having been previously "closed"):
 Application.Timer.Interval = 100 'milliseconds
 Application.Timer.Enabled = True

Then in my Applet code I attached the following code to the Application.OnTimer Event.
Public Sub EditSelectedPoint()
 'When the OnTimer event is fired, then Edit the selected feature.
 Dim objSelectionLayer
 Application.Timer.Enabled = False
 Set objSelectionLayer = Map.SelectionLayer
 If Not(objSelectionLayer Is Nothing) Then
  objSelectionLayer.Edit  Map.SelectionBookmark
 End If
End Sub

So far it seems to be working!
0 Kudos