I'm wondering if someone has or knows where a tool is to edit the 'Display Expression' of a Layer, or more specifically, a TableView, in ArcGIS Desktop. I know that it can't be accessed with Python, but it should be editable with ArcObjects. But this isn't something I know how to do yet.

I'm using a Python Add-in to add a Layer into ArcMAP which has a relate with a couple TableViews that I add at the same time. The trouble is that it always resets the field that is displayed in the identify window to something unhelpful.

Thanks for any suggestions.


You will need to use ArcObjects. You are looking for the IDisplayExpressionProperties interface. It is obtained from IDisplayString, which in turn is obtained from IFeatureLayer. Here you will find a fantastic little snippet of code provided by patrick that does the trick:

public void annotateLayer(ILayer thisLayer, String geocode, double minScale, double maxScale, bool annotationsOn, bool showMapTips, RgbColor annotationLabelColor)
   IGeoFeatureLayer geoLayer = thisLayer as IGeoFeatureLayer;
   if (geoLayer != null)
        geoLayer.DisplayAnnotation = annotationsOn;
        IAnnotateLayerPropertiesCollection propertiesColl = geoLayer.AnnotationProperties;
        IAnnotateLayerProperties labelEngineProperties = new LabelEngineLayerProperties() as IAnnotateLayerProperties;
        IElementCollection placedElements = new ElementCollectionClass();
        IElementCollection unplacedElements = new ElementCollectionClass();
        propertiesColl.QueryItem(0, out labelEngineProperties, out placedElements, out unplacedElements);
        ILabelEngineLayerProperties lpLabelEngine = labelEngineProperties as ILabelEngineLayerProperties;
        lpLabelEngine.Expression = geocode;
        lpLabelEngine.Symbol.Color = annotationLabelColor; 
        labelEngineProperties.AnnotationMinimumScale = minScale;
        labelEngineProperties.AnnotationMaximumScale = maxScale; 
        IFeatureLayer thisFeatureLayer = thisLayer as IFeatureLayer;
        IDisplayString displayString = thisFeatureLayer as IDisplayString;
        IDisplayExpressionProperties properties = displayString.ExpressionProperties;
        properties.Expression = geocode; //example: "[OWNER_NAME] & vbnewline & \"$\" & [TAX_VALUE]";
        thisFeatureLayer.ShowTips = showMapTips;

Note the variable "geocode" which is stored in properties.Expression. You can specify a single column name or a combination of different column names, or even a single variable.

| improve this answer | |
  • That looks great. I've been looking through the tutorials in the Arc SDK Help, but it's not clear to me how I can integrate something like this with Python. I'm wondering if I'd need to do the whole add-in in C#, which I know a bit of. Or is it possible to somehow wrap this in a way I can access it from Python? – cndnflyr Jun 27 '14 at 15:56
  • You need the Python comtypes package. See the Q/A here: gis.stackexchange.com/questions/80/… And also make the small tweak to the Python file here: gis.stackexchange.com/questions/37672/… – Conor Jun 27 '14 at 16:06
  • Ok, I had seen this and played with it, but never seriously tried to get it working. I wonder if I should bother though. This is something that will be given out to about 30 other users in our department and am unsure about making sure comtypes is available whenever the script is run. I maybe should just look into doing the add-in in C#. Thanks for your help! – cndnflyr Jun 27 '14 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.