Is there a way to show/hide the table of contents programmatically using ArcObjects?
Thanks
Solved! Go to Solution.
Yes. What you would need to do is grab the GUID of the table of contents and tell use that to turn the dockable window on or off. Here is a quick sample using C# and ArcObjects Addins. Tested at 10.2.2.
using System; using System.Collections.Generic; using System.Text; using System.IO; using ESRI.ArcGIS.Framework; using ESRI.ArcGIS.esriSystem; namespace ArcMapAddin10 { public class Button1 : ESRI.ArcGIS.Desktop.AddIns.Button { public Button1() { } protected override void OnClick() { // // TODO: Sample code showing how to access button host // //ArcMap.Application.CurrentTool = null; IApplication m_app = ArcMap.Application; IDockableWindowManager pDocWinMgr = m_app as IDockableWindowManager; UID uid = new UIDClass(); uid.Value = "{368131A0-F15F-11D3-A67E-0008C7DF97B9}"; IDockableWindow pTOC = pDocWinMgr.GetDockableWindow(uid); if (pTOC.IsVisible()) {pTOC.Show(false);} else { pTOC.Show(true); } } protected override void OnUpdate() { Enabled = ArcMap.Application != null; } } }
Shout out to Andrew Wang for the assistance in creating this sample.
The following documentation should be helpful as well:
IDockableWindow
Yes. What you would need to do is grab the GUID of the table of contents and tell use that to turn the dockable window on or off. Here is a quick sample using C# and ArcObjects Addins. Tested at 10.2.2.
using System; using System.Collections.Generic; using System.Text; using System.IO; using ESRI.ArcGIS.Framework; using ESRI.ArcGIS.esriSystem; namespace ArcMapAddin10 { public class Button1 : ESRI.ArcGIS.Desktop.AddIns.Button { public Button1() { } protected override void OnClick() { // // TODO: Sample code showing how to access button host // //ArcMap.Application.CurrentTool = null; IApplication m_app = ArcMap.Application; IDockableWindowManager pDocWinMgr = m_app as IDockableWindowManager; UID uid = new UIDClass(); uid.Value = "{368131A0-F15F-11D3-A67E-0008C7DF97B9}"; IDockableWindow pTOC = pDocWinMgr.GetDockableWindow(uid); if (pTOC.IsVisible()) {pTOC.Show(false);} else { pTOC.Show(true); } } protected override void OnUpdate() { Enabled = ArcMap.Application != null; } } }
Shout out to Andrew Wang for the assistance in creating this sample.
The following documentation should be helpful as well:
IDockableWindow
Great. Thanks. It works.
Any idea if you can hid any of the contents inside the TOC, specifically remove some of the icons. I'm really only interested in the 'List by Visibility section'
That I don't know, you may want to ask that question in a new forum post.