Situation : you have a layer in TOC, then right click and properties display, then go to Definition Query then Query Builder.
I been trying to mimic this procedure using Arc objects with C#,
as an example :
IQueryFilter pQueryfilter = new QueryFilterClass();
pQueryfilter.WhereClause = "Num ='" + comboBox2.Text + "'";
IFeatureSelection pfeatureselection = pFeatureLayer as IFeatureSelection;
pfeatureselection.SelectFeatures (pQueryfilter, esriSelectionResultEnum.esriSelectionResultNew, false);
but the code above it doesn't do what I want : the code above select the features eventually will zoom into......, but still, if I go to my table I can see all the records and highlighter the selected ones, I just want to see in my table those ones selected as it is under Query Builder. It is possible to do it?.
I know that there is a way to create a new layer from the selected features and added to the project depending in the selection but this is not what I want either.
Thanks
Solved! Go to Solution.
Just cast your layer to IFeatureLayerDefinition2 and set its DefinitionExpression property. This property is actually the same thing that you set via layer's properties definition query.
var featureLayerDefinition = featureLayer as IFeatureLayerDefinition2;
if (featureLayerDefinition != null)
featureLayerDefinition.DefinitionExpression = $"Num = '{comboBox2.Text}'";
Just cast your layer to IFeatureLayerDefinition2 and set its DefinitionExpression property. This property is actually the same thing that you set via layer's properties definition query.
var featureLayerDefinition = featureLayer as IFeatureLayerDefinition2;
if (featureLayerDefinition != null)
featureLayerDefinition.DefinitionExpression = $"Num = '{comboBox2.Text}'";
Thanks a lot, it did work perfectly.