Remove a join programmatically with C#

1739
0
07-26-2011 02:29 AM
DietmarPalmetzhofer
New Contributor III
Due to a bug in arcpy (removing a join between an SDE-featureclass and an ODBC-table fails) I was forced to make an add-in with C# in order to remove the join for many layers in a Mapdocument. After hourses of searching for a solution and messing around with RelationShipClass, I found a usefull example in the VBA-documentation (http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#/How_to_remove_the_last_joi...). So, if someone is having the same problem, here is the solution:
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
ESRI.ArcGIS.Carto.IActiveView actView = mxDocument.ActiveView;
IMap focMap = actView.FocusMap;

for (int i = 0; i < focMap.LayerCount; i++)
{
                IFeatureLayer2 actFeatLyr = focMap.get_Layer(i) as IFeatureLayer2;
                ITable actLyr = focMap.get_Layer(i) as ITable;
                IDisplayTable actDispTable = actFeatLyr as IDisplayTable;
                IRelQueryTable actQueryTable = actDispTable.DisplayTable as IRelQueryTable;
                IDisplayRelationshipClass actDispRelClass = actFeatLyr as IDisplayRelationshipClass;
                
                actDispRelClass.DisplayRelationshipClass(null, esriJoinType.esriLeftInnerJoin);
}
//Refreshing the view
actView.Refresh();

//Refreshing the TOC
ESRI.ArcGIS.ArcMapUI.IContentsView contentsView = mxDocument.CurrentContentsView;
            contentsView.Refresh(null);
0 Replies