bruce.nielsen

Adding a Modified Table to a Layout

Discussion created by bruce.nielsen on Aug 23, 2013
Latest reply on Aug 27, 2013 by bruce.nielsen
I have a featureclass that represents the soils data for a field. My goal is to only show the soil mapunit and acreage fields from the attribute in an existing layout. The following code makes the desired changes to the table:
Private Sub btnAddTable_Click(sender As Object, e As System.EventArgs) Handles btnAddTable.Click
        'Add a table to the layout for the selected tract/field
        Dim intASD As Integer = GetASDLayer() 'Returns the layer's position in the TOC
        If intASD >= 0 Then
            Dim pLayer As ILayer = pMxDoc.FocusMap.Layer(intASD)

            'Reduce the visible columns to just MUSYM and SUMACRES
            Dim pTableFields As ITableFields = pLayer
            Dim pFieldInfo As IFieldInfo3
            Dim pField As IField
            For x = 0 To pTableFields.FieldCount - 1
                pField = pTableFields.Field(x)
                pFieldInfo = pTableFields.FieldInfo(x)
                If pField.Name = "MUSYM" Then
                    'Keep and rename
                    pFieldInfo.Alias = "Soil Type"
                ElseIf pField.Name = "SUMACRES" Then
                    'Ditto
                    pFieldInfo.Alias = "Acres"
                Else
                    'Don't display anything else
                    pFieldInfo.Visible = False
                End If
            Next

            AddTableFrame(pLayer)
        End If

    End Sub

And if I open the attribute table from the TOC after running this routine, the table appears with the undesired fields removed. But when I add the table to the layout with this code:
Public Sub AddTableFrame(pTable As ITable)
        'Adapted from http://forums.esri.com/Thread.asp?c=93&f=992&t=57798&mc=22#msgid293581
        Dim pPageLayout As IPageLayout = pMxDoc.PageLayout
        Dim pGContainer As IGraphicsContainer = pPageLayout

        'Get the table of the first featureclass
        Dim pMap As IMap = pMxDoc.FocusMap

        'Create a new tableframe
        Dim pTableFrame As ITableFrame = New TableFrame
        Dim pElement As IElement = pTableFrame

        'Setup table properties
        pTableFrame.Table = pTable
        pTableFrame.StartCol = 0
        pTableFrame.StartRow = 0

        'Define frame bounds
        Dim pEnv As IEnvelope = New Envelope
        'Allow enough space for each row in the table + the header
        pEnv.PutCoords(0.5, 2.75 - (pTable.RowCount(Nothing) * 0.165 + 0.1875), 8, 2.75)

        Dim userRECT As tagRECT
        userRECT.top = 0
        userRECT.left = 0
        userRECT.right = pEnv.Width
        userRECT.bottom = pEnv.Height

        'Setup tableview properties
        Dim pTableView2 As ITableView2 = pTableFrame.TableView

        pTableView2.Table = pTable
        pTableView2.Show(0, userRECT, True)

        'Add the element to the specified spot
        pElement.Geometry = pEnv
        pGContainer.AddElement(pElement, 0)

        pMxDoc.ActiveView.Refresh()

    End Sub

The entire, unaltered table is displayed. How do I get the abridged table to appear in the layout?

Outcomes