# Get distinct column values of a FeatureSource with FeatureIdsToExclude property set

**URL:** <https://community.thinkgeo.com/t/get-distinct-column-values-of-a-featuresource-with-featureidstoexclude-property-set/5346>\
**Category:** WebForms\
**Created:** [June 7, 2010, 2:16pm UTC](https://community.thinkgeo.com/t/get-distinct-column-values-of-a-featuresource-with-featureidstoexclude-property-set/5346 "2010-06-07T14:16:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ching](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@Ching](https://community.thinkgeo.com/u/Ching)\
**Post date:** [June 7, 2010, 2:16pm UTC](https://community.thinkgeo.com/t/get-distinct-column-values-of-a-featuresource-with-featureidstoexclude-property-set/5346/1 "2010-06-07T14:16:29Z")

</div>

Hi,

I&nbsp;have&nbsp;a&nbsp;ShapeFileFeatureLayer&nbsp;which&nbsp;I&nbsp;set&nbsp;the&nbsp;FeatureIdsToExclude&nbsp;to&nbsp;exclude&nbsp;some&nbsp;features&nbsp;to&nbsp;be&nbsp;loaded.&nbsp;I&nbsp;also&nbsp;have&nbsp;a&nbsp;function&nbsp;that&nbsp;will&nbsp;get&nbsp;the&nbsp;distinct&nbsp;value&nbsp;of&nbsp;a&nbsp;column&nbsp;in&nbsp;that&nbsp;FeatureSource.&nbsp;The&nbsp;problem&nbsp;is&nbsp;it&nbsp;is&nbsp;getting&nbsp;the&nbsp;distinct&nbsp;values&nbsp;of&nbsp;entire&nbsp;shapefile&nbsp;column&nbsp;not&nbsp;the&nbsp;one&nbsp;with&nbsp;the&nbsp;excluded&nbsp;record.&nbsp;What&nbsp;should&nbsp;I&nbsp;do&nbsp;to&nbsp;only&nbsp;get&nbsp;the&nbsp;distinct&nbsp;column&nbsp;values&nbsp;with&nbsp;the&nbsp;excluded&nbsp;records?

&nbsp;

`	    private List<string> GetDistinctColumnValues(ShapeFileFeatureLayer shapeLayer, string column)	    {            shapeLayer.Open();	        string query = "select distinct [" + column + "] from " + Config.Current.ShapeFileTableName;            DataTable dt = shapeLayer.FeatureSource.ExecuteQuery(query);            shapeLayer.Close();	        List<string> values = new List<string>();	        foreach(DataRow dr in dt.Rows)	        {	            values.Add(dr[0].ToString());	        }	        return values;	    }`

---

<div class="post-metadata">

**Author:** ![Johnny](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/johnny/32/19044_2.png) [@Johnny](https://community.thinkgeo.com/u/Johnny)\
**Post date:** [June 8, 2010, 1:19am UTC](https://community.thinkgeo.com/t/get-distinct-column-values-of-a-featuresource-with-featureidstoexclude-property-set/5346/2 "2010-06-08T01:19:41Z")

</div>

Ching,&nbsp;  
&nbsp;&nbsp;  
&nbsp;There&nbsp;are&nbsp;ways&nbsp;to&nbsp;get&nbsp;it:&nbsp;  
&nbsp;&nbsp;  
&nbsp;1. Use&nbsp;shapeLayer.FeatureSource.GetFeaturesByIds&nbsp;to&nbsp;get&nbsp;all&nbsp;the&nbsp;excluded&nbsp;features,&nbsp;and&nbsp;then&nbsp;loop&nbsp;and&nbsp;filter&nbsp;the&nbsp;features&nbsp;to&nbsp;make&nbsp;sure&nbsp;it’s&nbsp;unique&nbsp;  
&nbsp;2. Modify&nbsp;the&nbsp;loop&nbsp;statement&nbsp;to&nbsp;filter&nbsp;all&nbsp;the&nbsp;features&nbsp;to&nbsp;make&nbsp;sure&nbsp;the&nbsp;collection&nbsp;just&nbsp;contain&nbsp;the&nbsp;unique&nbsp;excluded&nbsp;features.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;questions&nbsp;please&nbsp;let&nbsp;us&nbsp;know.&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Johnny&nbsp;
