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];
}
}