Query Builder

1017
2
Jump to solution
01-24-2017 03:58 PM
Jose_LuisGarcinuno-Oporto
New Contributor III

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

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MaxMax2
Occasional Contributor II

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}'";‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
MaxMax2
Occasional Contributor II

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}'";‍‍‍‍‍‍‍‍‍
Jose_LuisGarcinuno-Oporto
New Contributor III

Thanks a lot, it did work perfectly.

0 Kudos