Application error: ITableWindow2.Show

1933
1
12-05-2011 11:54 AM
LindaSmith
New Contributor
I am testing an ArcMap Extension that was written in .Net for ArcGIS 9.3.1 in ArcGIS 10.  One of the custom commands opens the Attribute table for selected features.  The command determines which layer the user wants to open attributes for and then calls the subroutine below to open the layers attribute table. When the ITableWindow2.Show(true) command is issued, ArcGIS 10 errors with "Atttempted to read or write protected memory".     Any help would be greatly appreciated.

Public Sub OpenSelectTable(ByVal layer As ILayer, ByVal SELSET As Boolean, ByVal papp As IApplication)
        Try


            Dim pMxDoc As IMxDocument
            Dim pLayer As ILayer
            Dim pStandaloneTable As IStandaloneTable
            Dim pTableWindow2 As ITableWindow2
            Dim pExistingTableWindow As IDataWindow2

            '  'Get the selected item from the current contents view
            pMxDoc = TryCast(papp.Document, IMxDocument)
            pTableWindow2 = New TableWindow
            ' Determine the selected item's type
            ' Exit sub if item is not a feature layer or standalone table
            'Continue = False
            If TypeOf layer Is IFeatureLayer And layer.Valid Then 'A FeatureLayer
                pLayer = layer
                pExistingTableWindow = TryCast(pTableWindow2.FindViaLayer(pLayer), IDataWindow2)
                ' Check if a table already exists; if not create one
                pTableWindow2.Layer = pLayer
            ElseIf TypeOf layer Is IStandaloneTable And layer.Valid Then
                ' A standalone table
                pStandaloneTable = TryCast(layer, IStandaloneTable)
                pExistingTableWindow = TryCast(pTableWindow2.FindViaStandaloneTable(pStandaloneTable), IDataWindow2)
                ' Check if a table already exists; if not, create one
                pTableWindow2.StandaloneTable = pStandaloneTable
            End If

            pTableWindow2.TableSelectionAction = esriTableSelectionActions.esriDrawFeatures

            pTableWindow2.ShowSelected = SELSET
            pTableWindow2.ShowAliasNamesInColumnHeadings = True
            pTableWindow2.Application = papp
            pTableWindow2.Show(True)

        Catch ex As Exception
            MsgBox("Error support/openselecttable: " & ex.Message)
        End Try
    End Sub
0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor
Linda,

I had a play with the ITableWindow2 Interface in VBA and found using your code I too could crash ArcMap.  I then played around with the properties and found this combination to work:

Public Sub x()
    Dim pMXDOC As IMxDocument
    Set pMXDOC = ThisDocument
    Dim pmap As IMap
    Set pmap = pMXDOC.FocusMap
    Dim pl As ILayer
    Set pl = pmap.Layer(0)
    Dim pTW2 As ITableWindow2
    Set pTW2 = New TableWindow
    With pTW2
        Set .Application = Application
        Set .Layer = pl
        .ShowAliasNamesInColumnHeadings = True
        .TableSelectionAction = esriSelectFeatures
        .Show True
        .ShowSelected = True
    End With
End Sub


I changed the selectionAction  but note I show the TableWindow THEN I show the selected...

Duncan
0 Kudos