Obtaining Results from a IdentifyResult

458
4
02-17-2011 05:03 AM
jonataspovoas
New Contributor III
Hi,
I'm developing an application, and in it i get information to populate a DataGrid from an Identify Function.

My problem is that the information needs to be in a very specific order, and i'm having trouble to obtain it.

I started studying the IDictionary and found, hoping to find out my salvation, but here's what i got so far:

public class DataItem
{
 public string Title { get; set; }
 public IDictionary<string, object> Data { get; set; }
}

//This is called after the results are found!
public void getIdentifyResults(List<IdentifyResult> results)
{
 _dataItems = new List<DataItem>();
 linhaDeObservações = new List<string>();
 if (results != null && results.Count > 0) 
 {
  IdentifyComboBox.Items.Clear();
  foreach (IdentifyResult result in results)
  {
   /* there can be more than oe result, each with several 
    * lines, which i must select a few.
    */
   Graphic LineCatcher = new Graphic();
   /* The following line should get lines by it's key (like "number", for example)
    * and will be repeated several times.
    */
   LineCatcher.Attributes.Add(result.Feature.Attributes.Where(/*Don't know what to put here*/);
   
   string title = result.Value.ToString() + " (" + result.LayerName + ")";
   _dataItems.Add(new DataItem() 
   {
    Title = title,
    Data = LineCatcher.Attributes
   });
   IdentifyComboBox.Items.Add(title);
  }
  IdentifyComboBox.SelectedIndex = 0;
 }
}


Anyone can help me?
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
What do you mean by "in specific order"? Do you mean sorted results or sorted field names?
0 Kudos
jonataspovoas
New Contributor III
What do you mean by "in specific order"? Do you mean sorted results or sorted field names?


Sorted Results.

the results come in an order and i need to change it.

Like:
-----------------------------
   Key | Value
-----------------------------
Cell number | 7897-7978
 Name | Joseph Climber
      Number | 129890 

-----------------------------
          Key | Value
-----------------------------
     Number | 129890 
        Name | Joseph Climber
Cell number | 7897-7978


I need sort the lines in an order that is neither alphabetical nor numeric
0 Kudos
jonataspovoas
New Contributor III
Hi,

I'm replying my reply to say that i finaly did it!

I'm posting here the solution:

MainPage.xaml
<UserControl x:Class="DataOrdering.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:slData="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    mc:Ignorable="d"
    d:DesignHeight="600" d:DesignWidth="800">

    <Canvas x:Name="LayoutRoot" Background="White">
        <slData:DataGrid x:Name="dadios" AutoGenerateColumns="False" HeadersVisibility="Column" Background="White" IsReadOnly="True" HorizontalScrollBarVisibility="Visible" Margin="8,15,-27,6" Height="165" Canvas.Left="4" Canvas.Top="37">
            <slData:DataGrid.Columns>
                <slData:DataGridTextColumn Width="Auto"  Binding="{Binding Key}" Header="Keys" FontWeight="Bold"/>
                <slData:DataGridTextColumn Width="Auto" Binding="{Binding Value}" Header="Values" />
            </slData:DataGrid.Columns>
        </slData:DataGrid>
    </Canvas>
</UserControl>

MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;

namespace DataOrdering
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            addResults();
        }

        private void addResults()
        {
            IDictionary<string, object> dataDictionary = new Dictionary<string, object>();
            dataDictionary.Add("Test", "Testado");
            dataDictionary.Add("ID", 10);
            dataDictionary.Add("id", "hhotbh");
            dataDictionary.Add("ThisGoesOnTop", "Qqr coisa");
            dataDictionary.Add("ThisGoesOnBottom", "oiyggfq");
            dadios.ItemsSource = order(dataDictionary);
            
        }

        public IDictionary<string, object> order(IDictionary<string, object> dataDictionary)
        {
            IDictionary<string,object> destiny = new Dictionary<string,object>();
            Dictionary<string, object> source = dataDictionary as Dictionary<string, object>;
            object value;
            
            if (source.TryGetValue("ThisGoesOnTop", out value)) destiny.Add("ThisGoesOnTop",value);
            if (source.TryGetValue("ID", out value)) destiny.Add("ID", value);
            if (source.TryGetValue("Test", out value)) destiny.Add("Test", value);
            if (source.TryGetValue("id", out value)) destiny.Add("id", value);
            if (source.TryGetValue("ThisGoesOnBottom", out value)) destiny.Add("ThisGoesOnBottom", value);

            return destiny;
        }
    }
}
0 Kudos
JenniferNery
Esri Regular Contributor
Ahh, you mean you want the results displayed in certain order according to their field names (not their values), where if results came back with Cell > Name > Number, you want to change the order to Number > Name > Cell.

In this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Identify, you need to modify ShowFeatures() where Data can no longer be set directly to feature.Attributes.

Without any change to this sample, click on Denver. For simplicity let's look at only 3 fields. Notice the order of these 3 fields: ObjectID > NAME > STATE_NAME. If you want to change the order in which they appear, you will need something like this to force them to be in a certain order.
private IDictionary<string, object> OrderedAttributes(IDictionary<string, object> source)
{
 IDictionary<string, object> result = new Dictionary<string, object>();
 List<string> orderedFields = new List<string>() { "STATE_NAME", "NAME", "ObjectID" };
 foreach (var f in orderedFields)
 {
  if (source.ContainsKey(f))
  {
   var item = source;
   result.Add(f, item);
  }    
 }
 return result;
}
0 Kudos