Select to view content in your preferred language

Show/Hide Table of Contents Programmatically

3751
3
Jump to solution
12-15-2014 11:37 AM
JosephSaltenberger
Deactivated User

Is there a way to show/hide the table of contents programmatically using ArcObjects?

Thanks

0 Kudos
1 Solution

Accepted Solutions
AlexanderNohe1
Honored Contributor

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

ArcObjects Help for .NET developers

View solution in original post

3 Replies
AlexanderNohe1
Honored Contributor

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

ArcObjects Help for .NET developers

JosephSaltenberger
Deactivated User

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'

0 Kudos
AlexanderNohe1
Honored Contributor

That I don't know, you may want to ask that question in a new forum post.