<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Referring to Attributes in a Query by Index number rather than name? in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111840#M2795</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The OutFields property only accepts either IEnumerable of field names or just * for all fields. However; there is a way of excluding certain fields after a QueryTask has been executed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The query should use * as its OutFields. In ExecuteCompleted event handler of your QueryTask loop through all Graphic objects in Features of the returned FeatureSet and remove the attribute in desired index before adding them to your GraphicsLayer. Here is a code snippet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
private void query_ExecuteCompleted(object sender, QueryEventArgs e)
{
&amp;nbsp;&amp;nbsp; FeatureSet featureSet = e.FeatureSet;
&amp;nbsp;&amp;nbsp; if (featureSet == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;
&amp;nbsp;&amp;nbsp; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
&amp;nbsp;&amp;nbsp; foreach (Graphic graphic in featureSet.Features)
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.Attributes.Remove(graphic.Attributes.ElementAt(0));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphicsLayer.Graphics.Add(graphic);
&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:42:08 GMT</pubDate>
    <dc:creator>AliMirzabeigi</dc:creator>
    <dc:date>2021-12-11T06:42:08Z</dc:date>
    <item>
      <title>Referring to Attributes in a Query by Index number rather than name?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111839#M2794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm doing a fairly standard query which then takes the first returned record and uses it to populate a DataGrid. I would like to be able to exclude one or more of the attribute fields that are returned from appearing in the DataGrid (in this case the first attribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know this can be easily done by specifying the fields by &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;name&lt;/SPAN&gt;&lt;SPAN&gt; when setting up the query like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;query.OutFields.AddRange(new string[] {"COMPANY_ID","COMPANY","AREA_SQ_MI","PERIM_MI","SOURCE","UPDATE_","NOTES","COMP_FULL" });&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I don't like hard-coding the field names in case the data set changes; I'd much rather just say 'exclude the field with the index value of 0.' I can see that there's the possibility of doing 'query.Outfields.Remove' or 'query.Outfields.RemoveRange' but can't get beyond that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm really tripping up on the syntax for this and I'm hoping it can be done fairly simply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another option seems to be sticking with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;query.OutFields.Add("*");&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then excluding that field once the query results are returned. Here's a condensed version of what I do with the results:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt; private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FeatureSet featureSet = args.FeatureSet;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Graphic selectedFeature = featureSet.Features[0];

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QueryDetailsDataGrid.ItemsSource = selectedFeature.Attributes;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Presumably there's a way of excluding the first attribute that is returned without using its name, but again I'm tripping up on how to achieve it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Carey&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Sep 2010 14:57:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111839#M2794</guid>
      <dc:creator>MatthewCarey</dc:creator>
      <dc:date>2010-09-17T14:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Referring to Attributes in a Query by Index number rather than name?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111840#M2795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The OutFields property only accepts either IEnumerable of field names or just * for all fields. However; there is a way of excluding certain fields after a QueryTask has been executed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The query should use * as its OutFields. In ExecuteCompleted event handler of your QueryTask loop through all Graphic objects in Features of the returned FeatureSet and remove the attribute in desired index before adding them to your GraphicsLayer. Here is a code snippet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
private void query_ExecuteCompleted(object sender, QueryEventArgs e)
{
&amp;nbsp;&amp;nbsp; FeatureSet featureSet = e.FeatureSet;
&amp;nbsp;&amp;nbsp; if (featureSet == null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;
&amp;nbsp;&amp;nbsp; GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
&amp;nbsp;&amp;nbsp; foreach (Graphic graphic in featureSet.Features)
&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphic.Attributes.Remove(graphic.Attributes.ElementAt(0));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; graphicsLayer.Graphics.Add(graphic);
&amp;nbsp;&amp;nbsp; }
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111840#M2795</guid>
      <dc:creator>AliMirzabeigi</dc:creator>
      <dc:date>2021-12-11T06:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Referring to Attributes in a Query by Index number rather than name?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111841#M2796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ali, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for the response. Maybe it's my mistake but this line brought up some errors for me:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;graphic.Attributes.Remove(graphic.Attributes.ElementAt(0));&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The errors are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error 1 The best overloaded method match for 'System.Collections.Generic.Dictionary&amp;lt;string,object&amp;gt;.Remove(string)' has some invalid arguments&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Error 2 Argument '1': cannot convert from 'System.Collections.Generic.KeyValuePair&amp;lt;string,object&amp;gt;' to 'string' &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any insight you have would be great, although please don't spend too much time on it as I realized that I could hard-code the field to &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;remove&lt;/SPAN&gt;&lt;SPAN&gt; rather than the ones to keep without it causing me too much hardship like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;graphic.Attributes.Remove("OBJECTID");&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Sep 2010 15:01:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/referring-to-attributes-in-a-query-by-index-number/m-p/111841#M2796</guid>
      <dc:creator>MatthewCarey</dc:creator>
      <dc:date>2010-09-23T15:01:33Z</dc:date>
    </item>
  </channel>
</rss>

