Table Events?

05-09-2012 07:21 AM
Regular Contributor

Does anyone know of any events for when a table is opened within ArcMap? For example right clicking on a layer and choosing "Open Attribute Table" or right clicking on the root database path and adding a table then opening that table? I'd like to be able to change the read only, highlight and visible states of the fields within tables that are opened. I know how to change the display of the table I just can't find a way to trap for when a table is opened.

I've found the ITableViewEvents Interface but it doesn't provide any methods for notification that a table has been opened.

0 Kudos
2 Replies
MVP Frequent Contributor

Interesting question this as I did not know of a solution to this. Things have been made more 'challenging' now that container window exists which holds all the tables. I've been thrashing around in ArcObjects and the best I could come up with is the following code that will wire up an event to a table once it has been opened. I'm hoping someone out there knows of a better solution?


Public WithEvents pDataWindowEvents As TableWindow
Public pTableWindow As ITableWindow3

Public Sub TableWindowTest()

' Create a TableWindow Object and add Application object to it
Set pTableWindow = New TableWindow
Set pTableWindow.Application = Application

' Get a handle on the open tables in TableWindow as a set object
Dim s As ISet
pTableWindow.FindOpenTableWindows s
Debug.Print "number of tables open in TableWindow: " & s.Count
If s.Count = 0 Then
    Debug.Print "Window not open!"
   ' Get first table from set object
   Dim pTW As ITableWindow
    Set pTW = s.Next
    ' Wire up event listener to this specific table
   Set pDataWindowEvents = pTW
    ' Get the Table object
   Dim pTable As ITable
    Set pTable = pTW.Table
    ' Report some info in debug
   Dim pDataset As IDataset
    Set pDataset = pTable
    Debug.Print "Returned Table: " & pDataset.Name
    Debug.Print "Number of rows:" & pTable.RowCount(Nothing)
End If
End Sub

Private Sub pDataWindowEvents_HideWindow(ByVal window As esriArcMapUI.IDataWindow)
    MsgBox "goodbye!"
End Sub

Private Sub pDataWindowEvents_ShowWindow(ByVal window As esriArcMapUI.IDataWindow)
    MsgBox "hello!"
End Sub
0 Kudos
Regular Contributor
Hi Duncan,

Yes, I already use that approach for other aspects of my solution. However, it doesn't answer the question. I couldn't find a way to be notified that a table had been opened either. I'll hold onto hope that someone out there has an answer. I'm wanting to be notified as the table is opened not when it's selected or by looping through already open tables.

0 Kudos