datagrid and highlighting results on map

2150
1
07-12-2012 08:33 AM
jerrysalinas
New Contributor
Hi,
I am trying to replicate the spatial query example found here http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery
The only issue I am having is with this line of code:   graphicsLayer.Graphics.Insert(0, feature);

I submit my query and I get the following error
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.

If I comment out the line above, it works fine, I get my results in the datagrid, but I am trying to highlight the points while hovering over the datagrid row. I've read most of the questions posted but can't get it to work.

private void QueryTask2_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;
            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No points found");
                return;
            }
           
            // If an item has been selected  
              GraphicsLayer graphicsLayer = this.CurrentPage.myMap.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;
            if (featureSet != null && featureSet.Features.Count > 0)
            {
    
                QueryDetailsDataGrid.ItemsSource = args.FeatureSet.Features;
                foreach (Graphic feature in featureSet.Features)
                {
                 feature.Symbol = QueryGrid.Resources["MyResultsMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                graphicsLayer.Graphics.Insert(0, feature);
                             }
                ResultsDisplay.Visibility = Visibility.Visible;
            }
        }

Thanks, Jerry
0 Kudos
1 Reply
JoeHershman
MVP Regular Contributor
Jerry,

My guess is something wrong when you try to get your GraphicsLayer,


    [LEFT]GraphicsLayer graphicsLayer = this.CurrentPage.myMap.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;[/LEFT]



are you sure that

MySelectionGraphicsLayer is a layer in your map.  I would add a check to make sure that graphicsLayer is not null

Thanks,
-Joe
0 Kudos