IRelationshipClassEvents events are not fired when using with class extension

2350
7
10-06-2010 08:26 PM
Udaya_BhaskerCheerala
New Contributor
Hi All,

I have developed a class extension in which Iam implementing IObjectClassEvents and IRelationshipClassEvents interface. The OnChange, OnCreate and OnDelete events of IObjectClassEvents are fired perfectly when feature is changed, created and deleted respectively. But IRelationshipClassEvents events(OnChange, Oncreate and OnDelete) are not fired when attributes in relation table is changed or relationship is created or relationship is deleted. am I missing anything? Please help me.

Thanks,
Uday
0 Kudos
7 Replies
vincentLahaye
New Contributor II
Hi,

you must set the same EXTCLSID for your FeatureClass and your related table in your geodatabase.

Vincent
0 Kudos
JamesMacKay
New Contributor
Hi Uday,

IRelationshipClassEvents is not an interface you can implement in a class extension in order to receive notifications. It offers subscription-style events that can be reached (assuming you're using .NET) by casting a relationship class to the IRelationshipClass_Event interface.

For a discussion of the differences between getting events in class extensions vs. subscription-style events, see the following:

http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/9dcfe2e3-7a5b-472f-b01c-da4e589676d3.htm

What you may want to look at are the IRelatedObjectClassEvents and IRelatedObjectClassEvents2 interfaces, as well as IConfirmSendRelatedObjectEvents. A section mid-way through the following article describes how to implement these on a class extension:

http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/6caed32d-8baf-4771-8bb4-2f350b7f0d7a.htm

Cheers,
James
0 Kudos
vincentLahaye
New Contributor II
You're right James,

i was talking about IRelatedObjectClassEvents2 and RelatedObjectChanged event, sorry.

James's links are good. 

But what i'm saying, it's from James's link : http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/6caed32d-8baf-4771-8bb4-2f350b7f0d7a.htm

you need to add the class extension GUID of your featureClass to your related table. In a PGDB you will find this in EXTCLSID field of a "GDB_" table.  But in FGDB you can't do this manually.  That's why you need to use "ChangeClassExtension" method from the James's link.  You need to add GUID of your featureclass, and use same GUID for your related table to this featureclass.

When you are leaving you FGDB and want use your featureclass outside of your extension, don't forget to remove EXTCLSID from your Featureclass and related table, else you will not be able to open your featureclass.  Just pass an empty GUID to  "ChangeClassExtension" method.

that worked fine for me.

Vincent
0 Kudos
Udaya_BhaskerCheerala
New Contributor
Hi Vincent,

Sorry for the late reply
I have added EXTCLSID to both Feature class and related table, but still the events are not firing.

Thanks,
Uday
0 Kudos
vincentLahaye
New Contributor II
Hi Uday,

be sure you created your extensionclass class with this link : http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/6caed32d-8baf-4771-8bb4-2f350b7f0d7a.htm

After this, implement IRelatedObjectClassEvents2 in this class.  Add GUI from this class to your EXTCLSID (and not CLSID) field in "GDB_ObjectClasses".  (ex: MainFeatureClass = {123456-...}, related table = {123456-...})

Be sure your extension was correctly registered.

With this, RelatedObjectChanged should be fire when you modify a data in related table.

Vincent
P.S. I don't think i forgot something, but it's possible.  I wrote this by memory.
0 Kudos
AndrewArace
New Contributor
Hi Uday,
I know this is an old thread but I'm recording my solution since your posts were the only ones with any substantial information when I encountered this same problem.

I have a system of class extensions that have been around since the 8.3 days, and after some recent 10.0 updates (and .NET ports) I started running into this same issue as you (despite implementing IRelationshipClassEvents on the class extension, no the IRelationshipClassEvents methods were not being called).

Background:
Feature class "A" with a relationship class "B".
Class extension registered on "A" that does a lot of detailed editing work.
EXTCLSID is only registered on the feature class "A", it has never been on "B" since it's inception and constant use since Arc 8.3 days despite the above posts, which just seem to be providing an overflow of information.

In the ArcMap, with a segment in "A" selected, and selecting a related row in the "B" destination table, right-clicking the attribute branch in the Attributes editor and selecting "Add Selected"
This used to cause the class extension's IRelationshipClassEvents.OnCreate implementation to be called.
SOLUTION: I finally figured out that IRelationshipClassEvents is not to used in that way, despite it really seeming like it should be. In fact, I'm not sure what it's used for at all.
I got around this by using the "other" event handling approach (using .NET event handlers) as mentioned in the above links.
In the class extension's Init() method, look through the relationship classes of "A" until you find "B", and cast the IRelationshipClass to a IRelationshipClassEvents_Event object, and bind the .NET event handlers:

        public void Init(IClassHelper ClassHelper, IPropertySet ExtensionProperties) {
            System.Diagnostics.Debug.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
            IObjectClass objClass = ClassHelper.Class as IObjectClass;
            IRelationshipClass relClass;
            IDataset relDataset;
            IEnumRelationshipClass enumRelClass = objClass.get_RelationshipClasses(esriRelRole.esriRelRoleAny);
            enumRelClass.Reset();
            relClass = enumRelClass.Next();
            while (relClass != null) {
                relDataset = relClass as IDataset;
                if (String.Compare(relDataset.Name, "B", true) == 0) {
                    IRelationshipClassEvents_Event eventCatcher = relClass as IRelationshipClassEvents_Event;
                    if (eventCatcher != null) {
                        eventCatcher.OnChange += new IRelationshipClassEvents_OnChangeEventHandler(eventCatcher_OnChange);
                        eventCatcher.OnCreate += new IRelationshipClassEvents_OnCreateEventHandler(eventCatcher_OnCreate);
                        eventCatcher.OnDelete += new IRelationshipClassEvents_OnDeleteEventHandler(eventCatcher_OnDelete);
                    }
                    break;
                }
                relClass = enumRelClass.Next();
            }
        }


        void eventCatcher_OnDelete(IRelationship rel) {
            System.Diagnostics.Debug.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }

        void eventCatcher_OnCreate(IRelationship rel) {
            System.Diagnostics.Debug.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }

        void eventCatcher_OnChange(IRelationship rel) {
            System.Diagnostics.Debug.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
        }


Hope this helps someone down the road.
-AA
0 Kudos
JosephKnieriem
New Contributor
This is the only thread I've found with any detailed information on this matter, so I'm going to post here.

Most of the discussions above involve communication between 2 feature classes.  I'm trying to go one step further and have 3 feature classes communicate.  I have feature classes A, B, and C.  A has a forward relationship with B, B has a forward relationship with C.  The goal is to have attribute updates in A force attribute updates in B, which in turn force attribute updates in C. 

I have one class extension on feature class C that implements IRelatedObjectClassEvents2 RelatedObjectChanged, which listens for changes in feature class B.  When I manually make an update to feature class B, as expected, the correct updates are made in feature class C. So that part is working.

Likewise, I have a class extension on feature class B that implements IRelatedObjectClassEvents2 RelatedObjectChanged, which listens for changes in feature class A.  Also as expected, when I manually make updates to feature class A, the expected changes are made on feature class B.  So this part is also working.

The problem I run into is that when I manually update Feature Class A and Feature Class B gets updated, the extension on Feature Class C doesn't fire the RelatedObjectChanged event.  As a result, my updates to feature class A aren't cascading all the way to feature class C.

What am I missing that is causing the event to not fire on feature class C?
0 Kudos