Definition Query or hide feature

Dec 7, 2010 at 6:14 PM
Edited Dec 7, 2010 at 6:14 PM


Is there a way to create a Definition query (like in ArcMap) or hide a feature from a shapefile in MW6?



Dec 7, 2010 at 7:58 PM

Ok, I figured it out.

IFeatureLayer featureLayer = (IFeatureLayer)UtilityFunctions.GetLayer("layerName"); 



Dec 7, 2010 at 8:04 PM

I'm not exactly sure what you mean by a definition query, but if you mean setting up a filter expression to restrict which shapes appear based on attributes you could do something like the following:

private void SetFilterExpression()
   FeatureSet fs = new FeatureSet();
  IMapFeatureLayer layer = map1.Layers.Add(fs);
   layer.Symbology.GetCategories().First().FilterExpression = "[State]='Texas'";

If you mean more like only showing a sub-range based on extent, you can use the FeatureSet.Select() method.



Dec 8, 2010 at 5:54 PM


Thank you. Actually, FeatureLayer.SetVisible() will work better for my scenario. But I am having some trouble with it.

I have a grid where I am displaying the records of the shapfile. I also have a link button in the grid that can be used to toggle the visibility of a feature.

I am able to hide a feature when the link button is clicked by using the FeatureLayer.SetVisible (int index, bool visible). But I am not able to turn it back again by using FeatureLayer.SetVisible (1,true).

Any suggestions? Is there another way to do this?

Thank you,


Dec 8, 2010 at 6:34 PM

Ok Its working now.

Using the index in FeatureLayer.SetVisible() was turning a feature off, but not showing it back again. But if you use a Feature in FeatureLayer.SetVisible() instead of an index works both ways.