0

I need send a IFeature element to a dockable window.

I tried creating a public static variable, in eManager Class, that is inicialized with a feature that catch a function:

public static IFeature pFeature;
    internal void ShowEntityDetails(IFeature feature)
    {
        pFeature = feature;
        IDockableWindow dockWindow = GetDockWindow(ThisAddIn.IDs.GMREAddin_Modules_Model_View_vEntityDetails);
        dockWindow.Show(true);
    }

And I get it in dockable window construct of this way:

public vEntityDetails()
    {
        InitializeComponent();
        IFeature pFeature = eManager.pFeature;
        if (pFeature == null) return;

        string streetName = pFeature.Value[pFeature.Fields.FindField("ALIAS")].ToString();
        MessageBox.Show(streetName);
    }

It only works the first time.

There any more professional way to do that?

2

There are several ways to skin this cat. I typically use an Addin Extension to manage most communications between components of the addin, including Dockable Windows.

In the Extension, for instance I have a global variable _DockWin and an Edit Event listener (where Events is the Editor cast as IEditEvents_Event):

private IDockableWindow _DockWin;

void Events_OnSelectionChanged()
{
    // See if dock win exists
    if (_DockWin == null) { _DockWin = GetDockWin(); }
    if (_DockWin == null) { return; }

    if (_Editor.SelectionCount > 0)
    {
        // pass the edit selection to a  method in the dockable window
        MyDockWinName.AddSelection(_Editor.EditSelection);
    }
}

In the above method I first attempt to get a reference to the Dock Win before continuing, using this method:

private IDockableWindow GetDockWin()
{
    // Only get/create the dockable window if they ask for it
    if (_DockWin == null)
    {
        UID dockWinId = new UID();
        dockWinId.Value = ThisAddIn.IDs.MyDockWinName;
        _DockWin = ArcMap.DockableWindowManager.GetDockableWindow(dockWinId);
    }
    return _DockWin;
}

The AddSelection method in the dockable window looks like this, but can do anything you wish to pass the information to a control. In my case, I pass selected features to a TreeView control (similar to the Editor Attribute Window). You first declare a global control variable (_tv), and in the constructor method assign a value (in my case the name of the control is tv).

public static TreeView _tv;

public MyDockWinName(object hook)
{
    InitializeComponent();
    this.Hook = hook;

    _tv = this.tv;
}

internal static void AddSelection(IEnumFeature editSelection)
{
    IEnumFeature enumFeat = editSelection;
    enumFeat.Reset();
    IFeature feature;

    int idx = -1;
    IFeatureClass fc = null;
    while ((feature = enumFeat.Next()) != null)
    {
        if (((IFeatureClass)feature.Class) != fc)
        {
            idx += 1;
            fc = (IFeatureClass)feature.Class;
            TreeNode tn = new TreeNode();
            tn.Text = fc.AliasName;
            tn.Tag = fc;
            _tv.Nodes.Add(tn);
        }
        TreeNode child = new TreeNode();
        child.Text = feature.OID.ToString();
        child.Tag = feature;
        _tv.Nodes[idx].Nodes.Add(child);
    }

    _tv.ExpandAll();

    if (_tv.Nodes.Count > 0)
    {
        _tv.SelectedNode = _tv.Nodes[0].Nodes[0];
    }
}
  • Thanks my friend, I created static variables and referenced them in my construct. – Pilgrim May 11 '17 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.