Update Cursors and Object Class Events…

We put a lot of business logic into Class Extensions tied in on the OnCreate, OnChange, and OnDelete Object Class Extension events. If an edit violates business logic, it is rolled back and the user is informed about what was wrong. This has been working quite smoothly until today when we started creating our Object Inspectors (see previous post).

What we found was that attribute edits done through our Object Inspector (and consequently ArcDAL) were not respecting the business logic. I dropped some breakpoints into the OnChange event in one of the class extensions, and found that it was not hit when we saved changes in the Object Inspector. Yet, when I opened the table editor I would see the changes, so I knew something was happening. Here’s the series of events graphically…

1) Original values in Object Inspector…

Media_httpblogdavebou_pjawy

2) District Name updated and saved

Media_httpblogdavebou_bhblj

3) Table editor shows the updated name, but OnChange event never fired!

Media_httpblogdavebou_slvph

4) When I try to edit the District Name via the table editor…

Media_httpblogdavebou_jffde

the OnChange event does fire, and the edit is rolled back because I do not have edit rights to that feature.

Media_httpblogdavebou_vhinn

We traced it back to using update cursors. Turns out that updating features via FeatureClass.Update in an edit session does not store changes to the base table until the edit session is saved. Thus, the ObjectClassExtension events do not fire until you “save” the edits and end the session. We need these events to fire as the edits occur so the user is informed when business rules are broken.

The solution was to just change back to using IFeature.Store – which correctly raises the events. This was just 4 simple edits, but we have 25 feature classes in our geodatabase model. Thanks to code-generation, we just made the edits in the templates, and re-generated all the classes.

This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Update Cursors and Object Class Events…

  1. Pedro Abreu says:

    Hi Dave,
    Some extensions force those events events with the update cursor (ex. Geometric Networks)… Maybe you should check the IWorkspaceEditControl.SetStoreEventsRequired()
    Thanks for your blog ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s