Refresh Currently Open Attribute Table using ArcObjects

5938
6
08-29-2012 01:01 PM
BrianBeck
New Contributor III
I have written an ArcMap Addin (ArcMap 10.0) that allows a user to perform a join between an in-memory table and a feature class (feature layer) added to the TOC. I want the attribute table of the feature layer to automatically refresh after the join occurs if the user happens to have the attribute table visible when performing the join. This way the fields added to the table via the join will be visible to the user without having to close and reopen the Attribute Table.

The following function is what I have tried to refresh the Attribute Table, but it does not actually refresh the display.

Private Sub RefreshAttributeTable()
    Try
        Dim tableWindow As ITableWindow3 = New TableWindow
        tableWindow.ActiveTableWindow.Refresh()

        My.ArcMap.Document.ActiveView.Refresh()
    Catch ex As Exception

        Debug.WriteLine(String.Format("{0}; {1}", ex.Message, ex.StackTrace))

    End Try
End Sub


Can anyone help with this?
Reply
0 Kudos
6 Replies
LeoDonahue
Regular Contributor
IMxDocument updateContents
Reply
0 Kudos
BrianBeck
New Contributor III
Thanks Leo,

I just tried that with no luck.  I did get it working, but not quite the way I'd like it to.  The only way I've been able to update the attribute table using arcobjects is to use:

Private Sub RefreshAttributeTable(ByRef featureLayer As IFeatureLayer2)
        Try

            Dim tableWindow As ITableWindow3 = New TableWindow

            Dim existingTable As ITableWindow3
            existingTable = tableWindow.FindViaLayer(CType(featureLayer, ILayer))

            existingTable.ShowSelected = Not existingTable.ShowSelected
            existingTable.ShowSelected = Not existingTable.ShowSelected

        Catch ex As Exception

            Debug.WriteLine(String.Format("{0}; {1}", ex.Message, ex.StackTrace))

        End Try
    End Sub


This is a little clunky because of the switching between selected and not selected twice, but it does the trick.  I just wish I knew what changing the ShowSelected property does behind the scenes to update the window.

IMxDocument updateContents
Reply
0 Kudos
SeanJones
Esri Regular Contributor
Firing ISelectionEvents.SelectionChanged (carto) usually does the trick.

http://forums.esri.com/thread.asp?c=93&f=992&t=118750&m=859399#369378
Reply
0 Kudos
BrianBeck
New Contributor III
Firing ISelectionEvents.SelectionChanged (carto) usually does the trick.

http://forums.esri.com/thread.asp?c=93&f=992&t=118750&m=859399#369378



Hi Sean,

Thanks for the help.  I just tried that and it didn't work either.  It seems that both suggestions I've seen refresh the map itself, but not the tables held in dockable windows.  Is there any documentation about the hierarchy of objects within the attribute table view in ArcMap.  For example, There are TableViews, TableControls, TableWindows, TableDockableWindowAdmins.  These are related to one another one way or another, but it is unclear exactly how they all interact from the API reference.
Reply
0 Kudos
DanielJordi
New Contributor
i finally found something that worked:

Dim tableWindow As ESRI.ArcGIS.ArcMapUI.ITableWindow = New ESRI.ArcGIS.ArcMapUI.TableWindow
tableWindow = tableWindow.FindViaFeatureLayer(fLayer, False)
tableWindow.Refresh()
GünterPrulamp
New Contributor II

    Public Sub RefreshTableWindows()

        Try

            Dim tableWindow3 As ITableWindow3 = New TableWindowClass

            Dim eSet As ESRI.ArcGIS.esriSystem.ISet = Nothing

            tableWindow3.FindOpenTableWindows(eSet)

            If eSet.Count > 0 Then

                eSet.Reset()

                Dim tw As ITableWindow = CType(eSet.Next, ITableWindow)

                Do While tw IsNot Nothing

                    If tw.IsVisible Then

                        tw.TableControl.RemoveAndReloadCache()

                        tw.TableControl.RereadFIDs(Nothing)

                        tw.TableControl.Redraw()

                    End If

                    tw = CType(eSet.Next, ITableWindow)

                Loop

            End If

        Catch ex As Exception

        End Try

    End Sub