HOW TO
It is possible to right-click one or more fields in an open table in ArcMap and select 'Freeze/Unfreeze Column'. Frozen fields move to the left-hand side of the table window and stay there as the horizontal scroll bar is used.
The following sample code shows how to perform this operation using ArcObjects. The code assumes that the attribute table contains five fields in the following order:
OBJECTID, SHAPE, NAME, FEA_CODE, SHAPE_LENGTH
Note:
Code in the Project's 'ThisDocument' code module will only run in the current map document. If you want to store the code in all your map documents open the Normal.mxt 'ThisDocument' code module instead.
Code:
Public Sub freezeFields()
' Start by getting the feature layer
' to be shown in a table window.
Dim pMxDoc As IMxDocument
Dim pFeatLayer As IFeatureLayer
Set pMxDoc = ThisDocument
Set pFeatLayer = pMxDoc.FocusMap.Layer(0)
' Open the feature layer in a table window.
Dim pTableWindow As ITableWindow
Set pTableWindow = New TableWindow
Set pTableWindow.FeatureLayer = pFeatLayer
Set pTableWindow.Application = Application
pTableWindow.ShowAliasNamesInColumnHeadings = True
' This will open the table in a window.
pTableWindow.Show True
' Get the properties for this table window.
Dim pTableProperties As ITableProperties
Dim pEnumTableProperties As IEnumTableProperties
Dim pTableProperty As ITableProperty
Set pTableProperties = pMxDoc.TableProperties
Set pEnumTableProperties = pTableProperties.IEnumTableProperties
pEnumTableProperties.Reset
Set pTableProperty = pEnumTableProperties.Next
' Re-order the fields so the ones to be frozen
' are on the left-side of the table window.
pTableProperty.FieldOrder _
= "NAME, FEA_CODE, OBJECTID, Shape, Shape_Length"
' Freeze the required number of fields,
' starting on the left-side of the table window.
pTableProperty.FrozenFields = 2 ' set to 0 to unfreeze.
' Refresh the table window.
' The fields NAME and FEA_CODE will be frozen.
Dim pTableControl As ITableControl
Set pTableControl = pTableWindow.TableControl
pTableControl.Redraw
End Sub
Article ID:000006094
Get help from ArcGIS experts
Download the Esri Support App