How to display only selected features in a featureclass in C#

472
8
Jump to solution
07-05-2012 06:42 PM
SreenivasaRaoPigili
Occasional Contributor
Hi All,

    i have situation like, in one of my featureclass we have 100 features.
    Using queryfilter we have selected only 20 features from total 100 featrues
   
Currently i am seeing all 100 features with 20 selection.

   Now my problem is, i have to display only 20 features in map.

Thanks in advance.
0 Kudos
1 Solution

Accepted Solutions
SreenivasaRaoPigili
Occasional Contributor
Hi,
   Thanks for your valuable suggestion.
   I have tried to use 'IFeatureLayerDefinition' in the below way.


                pFDef = (IFeatureLayerDefinition2)pFLayer2;
                pFDef.DefinitionExpression = "";
                pFDef.DefinitionExpression = "strColumn_Name='" + myObject.ToString() + "'";

                pActiveView = (IActiveView)pMap;
                pActiveView.Refresh();

But when i am running the code, in ArcMap I am getting ArcMap drawing error as "One or more layers failed to draw:"
Can you please suggest further.

View solution in original post

0 Kudos
8 Replies
AysberqTundra
Occasional Contributor
Hello.

You can switch off symbol of layer from Symbol Selector -> Symbol Property Editor window. In this case all 100 features will not be shown. But the result of query filter will be shown.
0 Kudos
SreenivasaRaoPigili
Occasional Contributor
Hi ,

  Thanks for your reply.
   But I am working in ArcObjects using C#.

   Can you please suggest in this regards.
0 Kudos
KenBuja
MVP Honored Contributor
Have you tried using an IFeatureLayerDefinition? This will display only the selected features as determined by a definition expression (which should be the same syntax as the whereclause in your queryfilter)
0 Kudos
JamesCrandall
MVP Frequent Contributor
Use IFeaturelayerDefintion and set the .DefinitionExpression with your SQL

edit: oops sorry Ken, you were first!
0 Kudos
SreenivasaRaoPigili
Occasional Contributor
Hi,
   Thanks for your valuable suggestion.
   I have tried to use 'IFeatureLayerDefinition' in the below way.


                pFDef = (IFeatureLayerDefinition2)pFLayer2;
                pFDef.DefinitionExpression = "";
                pFDef.DefinitionExpression = "strColumn_Name='" + myObject.ToString() + "'";

                pActiveView = (IActiveView)pMap;
                pActiveView.Refresh();

But when i am running the code, in ArcMap I am getting ArcMap drawing error as "One or more layers failed to draw:"
Can you please suggest further.

View solution in original post

0 Kudos
KenBuja
MVP Honored Contributor
There could be a couple of things at issue. Is 'strColumn_Name' the name of the field or a variable that hold the name of the field? If it's a variable, then you should use

pFDef.DefinitionExpression = strColumn_Name + "='" + myObject.ToString() + "'";

Is the field numeric instead of string? Then you would remove the single quotes from the string.

I would suggest comparing the DefinitionExpression value (use the debugging mode to see what it is exactly) with the expression that works properly in ArcMap
0 Kudos
SreenivasaRaoPigili
Occasional Contributor
Hi,
  Thanks for your reply Ken. But I have crossed-check once again through debugging. I am getting the proper value into the DefinitionExpressioin.
   Can anyone please share some sample code related to my problem.

Thanks.
0 Kudos
SreenivasaRaoPigili
Occasional Contributor
Hi All,
   Thanks for your suggestions. Now it is working fine by using IFeatureLayerDefinition2.
0 Kudos