sglover910

Getting add-ins to recognize & communicate with each other -- how?

Discussion created by sglover910 on Aug 2, 2011
Latest reply on Aug 6, 2011 by gkross
I am trying to build an ArcMap .NET/C# application that requires two related comboboxes, 'State' and 'County'.  'State' is populated at startup (from a geodatabase, although of course I could hard-code it).  I would like to populate 'County' from the geoDB **after** the user makes a selection in 'State'.  Of course, the idea here is to populate 'County' only with counties within the selected state.  It's a pretty straightforward thing in any other UI environment I've developed in, but none of the experiments I've tried so far have worked.

'County' dropdown class -- creates static, (quasi-) singleton reference, which 'should' get returned by calling CountySelectionComboBox.getSelf().  In theory the recipient of the getSelf () reference, should be able to use it to invoke DoWork (), and populate the dropdown.

    public class CountySelectionComboBox : ESRI.ArcGIS.Desktop.AddIns.ComboBox
    {
        private IWorkspace m_workspace = null;

        private static CountySelectionComboBox m_self;

        public CountySelectionComboBox()
        {
            m_self = this;

            this.Add("version 0.2", "version 0.2");
        }

        // One experimental attempt at 'getSelf ()'
        public CountySelectionComboBox getSelf()
        {
            return m_self;
        }

        // Another experiment; used instead of the one just above
        public static CountySelectionComboBox GetSelf()
        {
            // Extension loads just in time, call FindExtension to load it.
            if (null == m_self)
            {
                UID extID = new UIDClass();
                extID.Value = ThisAddIn.IDs.CountySelectionComboBox;
                ArcMap.Application.FindExtensionByCLSID(extID);
            }

            return m_self;
        }

        public static void DoWork()
        {
            string[] filler = { state, "alpha", "beta", "gamma", "delta" };

            for (int i = 0; i < filler.Length; i++)
            {
                m_self.Add(filler[i], filler[i]);
            }
        }
    }   // end class 'CountySelectionComboBox'


Here's the calling code from the 'State' add-in.  What I'm trying to do is look up the 'County' add-in by its (known) name, and then invoke getSelf(), doWork(), etc.  But the whole thing blows up as soon as I try to 'Find (county-dropdown-name)'.

 
           IDocument document = application.Document;
           ICommandBars commandBars = document.CommandBars;
           ICommandItem ci = commandBars.Find("Tools_Toolbar", false, false);
           ICommandBar cb = (ICommandBar) ci;

            // Version 1:  Catastrophic failure
            CountySelectionComboBox ctl =   
              (CountySelectionComboBox)cb.Find("CountySelectDropdown_CountySelectionComboBox", false);

            // Version 2:  Catastrophic failure also
            object ctl = cb.Find("CountySelectDropdown_CountySelectionComboBox", false);
            CountySelectionComboBox county = (CountySelectionComboBox) ctl;

            // Neither version reaches this point
            if (null != county)
            {
                county = CountySelectionComboBox.GetSelf();
                CountySelectionComboBox.DoWork("filler");
            }



Note that, since 'StateSelectionComboBox' and 'CountySelectionComboBox' are in separate assemblies and namespaces, 'getSelf()' and 'doWork()' are PUBLIC static, rather than INTERNAL static, as they were in the original sample code.

Anyway, I can kinda sorta see why all this wouldn't work, since an add-in's name isn't necessarily a unique identifier.  But there's got to be some way for an add-in to:

1) Determine what other add-ins exist in its session (or look for a particular add-in)

2) Get some kind of reference to the other add-in

3) Use that reference to invoke a particular method.

I mean, there **has** to be, right?  Thanks in advance.

Outcomes