Label Only Selected Features?

995
4
12-15-2011 12:48 PM
GeorgeFaraj
Occasional Contributor III
OK, I've been labeling using the LabelEngine and simple expressions and it is working for every layer. I want to offer the option of labeling only selected features and thought it would be this simple:

annotateLayerProperties.LabelWhichFeatures = esriLabelWhichFeatures.esriSelectedFeatures;


Unfortunately that doesn't do it. Every polygon is still labeled. I verified that the features were selected (I have a routine that just returns the selected keys.) I also tried replacing the Engine labeling with a:

annotateLayerProperties.WhereClause = BuildWhere( keyName, selected ); 


using both my keys and the features OIDs - that does not label at all.

Does anyone know how to label only the selected features?
0 Kudos
4 Replies
SiqiLi
by Esri Contributor
Esri Contributor
According to the API reference, both the LabelWhichFeatures method and WhereClause property should do what you need. Have you try to refresh the active view?

Here is a KB article shows how to "Label selected features in ArcMap using ArcObjects". It uses the IAnnotateLayerProperties::WhereClause property. The only difference I see is the KB calls the IActiveView.Refresh method at the end.
http://support.esri.com/en/knowledgebase/techarticles/detail/21092

I apologize that the above KB is a very old one, however all the ArcObjects used in the KB hasn't been changed. So please give it a try. Thanks.
0 Kudos
GeorgeFaraj
Occasional Contributor III
Already tried that suggestion. I don't think ArcGIS has the capability of labeling only selected features. My actual problem is worse that however.  The esriSelectedFeatures setting should work if you are then converting your label to an annotation but it is impossible to do that because my attributes are derived from a feature joined with a SQL Server table. I think I am stuck. :eek:
0 Kudos
sapnas
by
Occasional Contributor III
Did you clear the annotationproperties before applying new condition?
0 Kudos
GeorgeFaraj
Occasional Contributor III
Did you clear the annotationproperties before applying new condition?


Yes, it turns out that the .WhereClause will work but it will only work if I ensure that the field names are not delimited.
0 Kudos