<?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: Populating DataGrid from quering online image services in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035570#M9882</link>
    <description>&lt;P&gt;Thanks MaximilianGlas. This worked well for me. But still I am not able show the results in the data grid. I tried to bind the query results to the datagrid using the following code.&lt;/P&gt;&lt;P&gt;Code Snippet&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; // Query each of the sublayers with the query parameters.
                FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(citiesNameQuery);
                FeatureQueryResult countiesQueryResult = await countiesTable.QueryFeaturesAsync(countiesNameQuery);
                FeatureQueryResult statesQueryResult = await statesTable.QueryFeaturesAsync(statesNameQuery);

                var foundCities = 0;
                var foundCounties = 0;
                var foundStates = 0;

                // Loop through results, count the matches found in each layer.
                foreach (Feature city in citiesQueryResult)
                {
                    foundCities++;
                }

                foreach (Feature county in countiesQueryResult)
                {
                    foundCounties++;
                }
                foreach (Feature states in statesQueryResult)
                {
                    foundStates++;
                }

                // Report the number of matches for each layer.
                var msg = $"Found {foundCities} cities, {foundCounties} counties, and {foundStates} states containing {SearchTextBox.Text}" +
                    $" in a Name attribute.";
                MessageBox.Show(msg);

                // Bind the results to a DataGrid Control on the page
                MyDataGrid.ItemsSource = citiesQueryResult;
                MyDataGrid.ItemsSource = countiesQueryResult;
                MyDataGrid.ItemsSource = statesQueryResult;
            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 18:07:35 GMT</pubDate>
    <dc:creator>ManishShrivastav</dc:creator>
    <dc:date>2021-03-11T18:07:35Z</dc:date>
    <item>
      <title>Populating DataGrid from quering online image services</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035328#M9877</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to develop a WPF app that can populate a datagrid by querying an online image service.&amp;nbsp;&lt;A href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" target="_self"&gt;http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer&lt;/A&gt;&amp;nbsp; Particularly, I want to search for a name from the sublayers (search for a city, county, or state) and populate the result in a datagrid. I am attaching an image of the result that I want to have and an image of error message that I got. Also I am attaching the code file.&lt;/P&gt;&lt;P&gt;please help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Tasks;
using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MapApp
{
    /// &amp;lt;summary&amp;gt;
    /// Interaction logic for MainWindow.xaml
    /// &amp;lt;/summary&amp;gt;
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Map myMap = new Map(Basemap.CreateImagery());
            ArcGISMapImageLayer layer = new ArcGISMapImageLayer(new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer"));
            myMap.OperationalLayers.Add(layer);
            MyMapView.Map = myMap; 
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ArcGISMapImageLayer usaMapImageLayer = (ArcGISMapImageLayer)MyMapView.Map.OperationalLayers[0];

            try
            {
                // Use a utility method on the map image layer to load all the sublayers and tables.
                await usaMapImageLayer.LoadTablesAndLayersAsync();

                // Get the sublayers of interest.
                ArcGISMapImageSublayer citiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[0];
                ArcGISMapImageSublayer countiesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[3];
                ArcGISMapImageSublayer statesSublayer = (ArcGISMapImageSublayer)usaMapImageLayer.Sublayers[2];

                // Get the service feature table for each of the sublayers.
                ServiceFeatureTable citiesTable = citiesSublayer.Table;
                ServiceFeatureTable countiesTable = countiesSublayer.Table;
                ServiceFeatureTable statesTable = statesSublayer.Table;

                // Create the query parameters that will find features.
                QueryParameters citiesNameQuery = new QueryParameters
                {
                    WhereClause = "AREANAME=" + SearchTextBox.Text,
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };
                QueryParameters countiesNameQuery = new QueryParameters
                {
                    WhereClause = "NAME=" + SearchTextBox.Text,
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };
                QueryParameters statesNameQuery = new QueryParameters
                {
                    WhereClause = "STATE_NAME=" + SearchTextBox.Text,
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };

                // Query each of the sublayers with the query parameters.
                FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(citiesNameQuery);
                FeatureQueryResult countiesQueryResult = await citiesTable.QueryFeaturesAsync(countiesNameQuery);
                FeatureQueryResult statesQueryResult = await citiesTable.QueryFeaturesAsync(statesNameQuery);

                var foundCities = 0;
                var foundCounties = 0;
                var foundStates = 0;

                // Loop through results, count the matches found in each layer.
                foreach (Feature city in citiesQueryResult)
                {
                    foundCities++;
                }

                foreach (Feature county in countiesQueryResult)
                {
                    foundCounties++;
                }
                foreach (Feature states in statesQueryResult)
                {
                    foundStates++;
                }

                // Report the number of matches for each layer.
                var msg = $"Found {foundCities} cities, {foundCounties} counties, and {foundStates} states containing {SearchTextBox.Text}" +
                    $"in a Name attribute.";
                MessageBox.Show(msg);

                // Bind the results to a DataGrid Control on the page
                MyDataGrid.ItemsSource = citiesQueryResult;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 766px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8190iE7353814C6110D4F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Error.JPG" style="width: 587px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8191iFFD353CC312C15D4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Error.JPG" alt="Error.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 05:39:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035328#M9877</guid>
      <dc:creator>ManishShrivastav</dc:creator>
      <dc:date>2021-03-11T05:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Populating DataGrid from quering online image services</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035363#M9879</link>
      <description>&lt;P&gt;You have 2 issues in your code. That's the correct way.&lt;/P&gt;&lt;P&gt;WhereClauses are missing a quote:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                QueryParameters citiesNameQuery = new QueryParameters
                {
                    WhereClause = $"AREANAME='{SearchTextBox.Text}'",
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };
                QueryParameters countiesNameQuery = new QueryParameters
                {
                    WhereClause = $"NAME='{SearchTextBox.Text}'",
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };
                QueryParameters statesNameQuery = new QueryParameters
                {
                    WhereClause = $"STATE_NAME='{SearchTextBox.Text}'",
                    Geometry = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry,
                    OutSpatialReference = MyMapView.SpatialReference
                };&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you referenced the same table three times, you need to use the associated tables:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(citiesNameQuery);
                FeatureQueryResult countiesQueryResult = await countiesTable.QueryFeaturesAsync(countiesNameQuery);
                FeatureQueryResult statesQueryResult = await statesTable.QueryFeaturesAsync(statesNameQuery);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then it will work.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 08:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035363#M9879</guid>
      <dc:creator>MaximilianGlas</dc:creator>
      <dc:date>2021-03-11T08:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Populating DataGrid from quering online image services</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035570#M9882</link>
      <description>&lt;P&gt;Thanks MaximilianGlas. This worked well for me. But still I am not able show the results in the data grid. I tried to bind the query results to the datagrid using the following code.&lt;/P&gt;&lt;P&gt;Code Snippet&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; // Query each of the sublayers with the query parameters.
                FeatureQueryResult citiesQueryResult = await citiesTable.QueryFeaturesAsync(citiesNameQuery);
                FeatureQueryResult countiesQueryResult = await countiesTable.QueryFeaturesAsync(countiesNameQuery);
                FeatureQueryResult statesQueryResult = await statesTable.QueryFeaturesAsync(statesNameQuery);

                var foundCities = 0;
                var foundCounties = 0;
                var foundStates = 0;

                // Loop through results, count the matches found in each layer.
                foreach (Feature city in citiesQueryResult)
                {
                    foundCities++;
                }

                foreach (Feature county in countiesQueryResult)
                {
                    foundCounties++;
                }
                foreach (Feature states in statesQueryResult)
                {
                    foundStates++;
                }

                // Report the number of matches for each layer.
                var msg = $"Found {foundCities} cities, {foundCounties} counties, and {foundStates} states containing {SearchTextBox.Text}" +
                    $" in a Name attribute.";
                MessageBox.Show(msg);

                // Bind the results to a DataGrid Control on the page
                MyDataGrid.ItemsSource = citiesQueryResult;
                MyDataGrid.ItemsSource = countiesQueryResult;
                MyDataGrid.ItemsSource = statesQueryResult;
            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 18:07:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/populating-datagrid-from-quering-online-image/m-p/1035570#M9882</guid>
      <dc:creator>ManishShrivastav</dc:creator>
      <dc:date>2021-03-11T18:07:35Z</dc:date>
    </item>
  </channel>
</rss>

