Set Active TableWindow

628
2
11-12-2012 09:37 AM
QuinnKorbulic1
New Contributor III
Hello,

I'd like to be able to set an active tablewindow (or tab). Using ITableWindow3.ActiveTableWindow, I can get the active tab but cannot set it.

This is my basic setup:

A user runs a tool that selects some features. If the table for the layer is not already open, the table is opened and is automatically set as the active tab in the Table window. If the table is already open along with other tables and is not the active tab, the selection is updated, but the table is not set as the active tab in the table window.

Obviously, there is no set property for ITableWindow3.ActiveTableWindow (link to ArcObjects reference) but is there another way to do this?

Thanks
0 Kudos
2 Replies
DubravkoAntonic
New Contributor III
Tried to find solution for you.
I think solution is in
ITableDockWindowAdmin pTabWindowAdmin = new TableDockWindowClass();
pTabWindowAdmin.Show(ITableWindow, bool)


but ITableDockWindowAdmin keeps me bringing exception. I must be missing some initialization class.


I managed to open Table dialog:

IFeatureLayer pFeatureLayer = FindLayer("LayerName");
ITableWindow pTW = new TableWindowClass();
ITableWindow pTW_Layer = pTW.FindViaFeatureLayer(pFeatureLayer, true);
// windows not open if null
if (pTW_Layer == null)
{[INDENT]// Open datatable in Table window
[/INDENT]
[INDENT]ITableWindow pTableWindow = new TableWindowClass();
pTableWindow.FeatureLayer = pFeatureLayer;
pTableWindow.Application = ArcMap.Application;
if (!pTableWindow.IsVisible)
[/INDENT]
[INDENT=2]pTableWindow.Show(true);

[/INDENT]
[INDENT]return;
[/INDENT]
}



Tried with Win32APi but no luck, not responding properly to the SetWindowPos and ShowWindow API.

Hopefully someone would had more ideas to solve this problem.

Regards Dubravko
0 Kudos
DubravkoAntonic
New Contributor III
Finally got it to work correctly.
It was easy to add new table but it was at first hard to figure out how to activate existing table. But the cathc is in pTableWindow.Application = ArcMap.Application; If you look you will se that we got existing ITableWindows that had defined Application property and therefore show will not add them to existing ITableWindows but will reference to existing ITableWindow  and make it visible.

Change variable names if you like and enjoy!



IFeatureLayer pFeatureLayer = FindLayer("LayerName");
ITableWindow pTableWindow = new TableWindowClass();
ITableWindow pTW_Layer = pTableWindow.FindViaFeatureLayer(pFeatureLayer, true);
// windows not open if null
if (pTW_Layer == null)
{
    // Create TableWindow and add to Application
    ITableWindow pTableWindow = new TableWindowClass(); 
    pTableWindow.FeatureLayer = pFeatureLayer; 
    pTableWindow.Application = ArcMap.Application;
    pTableWindow.Show(true);
    return;
}
else
{
    // version 1
    if (!pTW_Layer.IsVisible)
           pTW_Layer.Show(true);
    return;

    // version 2
    ITableWindow3 pTableWindow3 = pTableWindow as ITableWindow3;
    ESRI.ArcGIS.esriSystem.ISet pTableSet = new ESRI.ArcGIS.esriSystem.SetClass();                    
    pTableWindow3.FindOpenTableWindows(out pTableSet);
    pTableSet.Reset();
    ITableWindow pTableWindowTemp = pTableSet.Next() as ITableWindow;
    while (pTableWindowTemp != null)
    {
        if (pTableWindowTemp.FeatureLayer.FeatureClass.FeatureClassID ==
            pFeatureLayer.FeatureClass.FeatureClassID)
        {
            if (!pTableWindowTemp.IsVisible)
                pTableWindowTemp.Show(true);
            return;
        }

        pTableWindowTemp = pTableSet.Next() as ITableWindow;
    }
}
0 Kudos