What does the IDockableWindow.UserData Property actually return?

671
4
06-03-2014 09:53 AM
DuncanHornby
MVP Notable Contributor
ESRI/ArcObject Gurus.

I have developed a dockable window as an AddIn using VB .Net. When you use the Wizard to create the AddIn it creates a UserControl which one populates with drop downs, text boxes etc. This all works fine.

I have created a COM object so this compiles to a separate DLL which is referenced by MS Access. This COM object starts an instance of ArcMap and needs to pass a value from an Access form to a textbox on the Dockable Window. I can get a handle on the window using the IDockableWindowManager.GetDockableWindow Method but I can't figure out how to drill down to the Textbox. Presumably its via the UserData property? If I get the object returned by this property and run it through TypeName function it simply says its IUnknown.

Various threads on the forum and searches point to this blog. But this method requires you to be able to access the AddIn so you are running code within the ArcMap framework. The Addin is a file only understood by ArcMap and not something that MS Access can reference.

So my question is what is the object returned by UserData property, the help page on this topic is decidedly unhelpful?

Has anyone worked out how to cast what ever it returns into a usercontrol where you can drill down to the various controls on it?

I very much look forward to any advice on this as I have hit the "wall".
0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
I've never created one as an add-in, but with the standard COM implementation the UserData property is something you can implement yourself.  It can return anything you set it to return since it's typed as Object.  In one implementation we've created, we return the user control.  In this case, you can access the controls it houses via its Controls collection.  In another implementation we return a custom object class we created to allow the passing of data via properties on that class.  I would imagine with an add-in you could override the property to return whatever you want but I don't know that for sure.
0 Kudos
DuncanHornby
MVP Notable Contributor
Hi Neil, Many thanks for your advice. I am going to be at a training course for the next few days so when I am back I will have ago at what you suggested, unless someone swoops in with the killer answer! Either way I will report back on this thread as I think there is very little help on this subject. Come on esri put some examples in the help file showing how to use userdata!
0 Kudos
by Anonymous User
Not applicable
I ran into the same problem when converting an old com sample to add-in a while ago.

IDockableWindow.UserData only works in the COM environment. Dockwindows created by add-ins return nothing. To get at the dockwindow and its contents you'll have to reference the window through the AddinImpl inner class as mentioned in that blog. This class is created through the add-in wizard when creating the docwin.

As an example I had a dockwindow containing a checkedlistbox that would host a bunch of snap agent's.
In the dockwindow class I exposed the control as public property.

    public CheckedListBox ListBox
    {
      get { return featureSnapAgentListBox; }
    }


I could then reference the listbox from the application with the following.

    protected override void OnClick()
    {
      ZSnapDockableWindow zsdw = AddIn.FromID<ZSnapDockableWindow.AddinImpl>(ThisAddIn.IDs.ZSnapDockableWindow).m_windowUI;

      //This line uses the UserData property to return the textbox embedded in the 
      //dockable window (child form). Only works in COM.
      //CheckedListBox featureSnapAgentListBox = (CheckedListBox)_dockableWindow.UserData;
      CheckedListBox featureSnapAgentListBox = zsdw.ListBox as CheckedListBox;
      featureSnapAgentListBox.Items.Clear();
      featureSnapAgentListBox.CheckOnClick = true;

      //Add the snapagents...


Hope this helps. I'll have a chat to the framework team about documentation.
0 Kudos
DuncanHornby
MVP Notable Contributor
Neil/Sean/Others,

I just can't seem to hook into the AddinImpl class of my Dockable Window in the AddIn from within my COM Class in MS Access. Even if I add a reference to the AddIn I am not successful.  😞

As always there is usually an alternate way and what I have done works because I have a static folder location which I need to create files in as this is how Access picks up on any selection that the user has made in ArcMap.

I've discovered the rather nifty FileSystemWatcher and so I dropped this component on my dockable window form and set the Changed/Created event to monitor the creation and update of a text file which holds an ID number created by Access.  As this file only ever changes when the user does something in Access then the dockable window reacts and updates the text box. 🙂

I mention this here if people are having problems connecting to controls in AddIns from COM classes being called in VBA...

Duncan
0 Kudos