How to add ITable to ArcMap TOC

1650
2
Jump to solution
07-16-2012 07:50 AM
YimanSong
New Contributor III
Is there anyway to add ITable to ArcMap TOC? I'm trying to edit a table which is added through WorkspaceFactory.OpenFromFile. But I get the error "Error HRESULT E_FAIL has been returned from a call to a COM component", see the code below. I found out that if I add a featurelayer along with the table and add the featurelayer to TOC, I don't get the error. Any suggestions?

            IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactory();             IWorkspace workspace = pWorkspaceFactory.OpenFromFile(path, 0);             IPropertySet propSet = workspace.ConnectionProperties;              IFeatureWorkspace pWorkspace = pWorkspaceFactory.Open(propSet, 0) as IFeatureWorkspace;             ITable table = pWorkspace.OpenTable("GISLCSA.GISEDITOR.MetaID");             ILayer tableLayer = table as ILayer;             pMetaIDTable = table as ITable;              UID uid = new UIDClass();             uid.Value = "esriEditor.Editor";             IEditor editor = m_application.FindExtensionByCLSID(uid) as IEditor;              if (editor.EditState == esriEditState.esriStateNotEditing)             {                 try                 {                     editor.StartEditing(workspace );                 }                 catch (Exception e)                 {                     MessageBox.Show(e.Message);                 }             }
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
You can create a new IStandaloneTable, set it's Table and Name properties and add it to the map via IStandaloneTableCollection.  You could also just start your edit session using IWorkspaceEdit instead of using the Editor extension.

View solution in original post

0 Kudos
2 Replies
NeilClemmons
Regular Contributor III
You can create a new IStandaloneTable, set it's Table and Name properties and add it to the map via IStandaloneTableCollection.  You could also just start your edit session using IWorkspaceEdit instead of using the Editor extension.
0 Kudos
YimanSong
New Contributor III
Perfect! Thank you Neil!
You can create a new IStandaloneTable, set it's Table and Name properties and add it to the map via IStandaloneTableCollection.  You could also just start your edit session using IWorkspaceEdit instead of using the Editor extension.
0 Kudos