Select to view content in your preferred language

Query Related Records Modification

569
1
10-26-2012 12:52 PM
TanyaOwens
Occasional Contributor III
Hi all,

I am using the sample code from http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords to query related records on my map. I would like to put in a condition that states if there is only 1 record selected to automatically display the related records in the treeview. I am, as usual stumped on how to do this. I am assuming it needs to be written into the SelectedItemChanged event, is this correct? If so, I am not seeing what is stopping the related data to automatically show up in the datagrid as it is now.

Thanks!!
0 Kudos
1 Reply
GreggBreton
New Contributor III
Hello Tanya,

You can try this

void QueryTask3_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            if (featureSet != null && featureSet.Features.Count > 0)
            {
                SelectedSitesTreeView.Tag = featureSet.ObjectIdFieldName;
                SelectedSitesTreeView.ItemsSource = featureSet.Features;
                int count = 0;
                Graphic newValue = null;
                foreach (Graphic g in featureSet.Features)
                {
                    g.Symbol = LayoutRoot.Resources["SelectMarkerSymbol"] as MarkerSymbol;
                    graphicsLayer.Graphics.Add(g);
                    newValue = g;
                    count = count + 1;
                }
                SelectedSitesTreeView.Visibility = System.Windows.Visibility.Visible;

                // If there was only one graphic, change the data grid the value of this graphic/feature.
                if (count == 1)
                {
                    RoutedPropertyChangedEventArgs<object> changedGraphics = new RoutedPropertyChangedEventArgs<object>(null, newValue);
                    SelectedSitesTreeView_SelectedItemChanged(sender, changedGraphics);    
                }
            }
            else
            {
                SelectedSitesTreeView.Visibility = System.Windows.Visibility.Collapsed;
                MessageBox.Show("No samples found here, please try another location.");
            }
        }
  
0 Kudos