GraphicsLayer selectionGraphicslayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; selectionGraphicslayer.ClearGraphics();
<Grid Style="{StaticResource WrapperStyle}"> <chartingToolkit:Chart Title="AnimationSequence = FirstToLast" Palette="{StaticResource GrowPieDataPointPalette}" Style="{StaticResource ChartStyle}" MouseLeftButtonDown="OnMouseLeftButtonDown" Margin="1,4,-1,-4"> <chartingToolkit:Chart.Series> <chartingToolkit:PieSeries ItemsSource="{Binding ElementName=Map, Path=Layers[MySelectionGraphicsLayer].Graphics}" DependentValueBinding="{Binding Attributes[DISPDESC]}" AnimationSequence="FirstToLast"/> </chartingToolkit:Chart.Series> </chartingToolkit:Chart> </Grid>
<Grid> <Grid.RowDefinitions> <RowDefinition Height="15" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock x:Name="DataDisplayTitle" Text="Search Results" FontSize="9" Grid.Row="0" FontWeight="Bold" FontFamily="Arial" Foreground="#FFFFFFFF" /> <esriWidgets:FeatureDataGrid Grid.Row="1" x:Name="QueryDetailsDataGrid" Height="170" Map="{Binding ElementName=Map}" GraphicsLayer="{Binding Layers[MySelectionGraphicsLayer], ElementName=Map}" /> </Grid>
<chartingToolkit:PieSeries IsSelectionEnabled="True"SelectionChanged="PieSeries_SelectionChanged" ItemsSource="{Binding}"
tags.
private void PieSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
foreach (Graphic item in selectionGraphicslayer.Graphics) item.Selected = false;I have to jump through the for loop X times for X amount of points/graphics...seems right.
{ QueryDetailsDataGrid.SelectedItems.Add(graphic); graphic.Select(); }
QueryDetailsDataGrid.SelectedItems.Add(graphic);
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { FeatureSet featureSet = args.FeatureSet; QueryDetailsDataGrid.ItemsSource = featureSet.Features;
foreach (var graphic in attributeGroup.Graphics) { if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic)) QueryDetailsDataGrid.SelectedItems.Add(graphic); graphic.Select(); }That should avoid the crash but the rows will probably not get selected if there is an issue with the initialization of ItemsSource.
When and How is set the ItemsSource of your QueryDetailsDataGrid?
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { FeatureSet featureSet = args.FeatureSet; QueryDetailsDataGrid.ItemsSource = featureSet.Features;
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args) { FeatureSet featureSet = args.FeatureSet; if (featureSet == null || featureSet.Features.Count < 1) { MessageBox.Show("No features retured from query"); return; } GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer; if (featureSet != null && featureSet.Features.Count > 0) // ResultsDisplay.Visibility = Visibility.Visible; { foreach (Graphic feature in featureSet.Features) { switch (featureSet.GeometryType.ToString()) { case "Polygon": feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol; break; case "Polyline": feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol; break; case "Point": feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol; break; } graphicsLayer.Graphics.Insert(0, feature); } //ResultsDisplay.Visibility = Visibility.Visible; ResultsDisplay.IsExpanded = true; } MyDrawSurface.IsEnabled = false; // PIE CHART - create an enumeration of AttributeGroup from the graphics in your layer DataContext = graphicsLayer.Graphics.GroupBy(graphic => (string)graphic.Attributes["TYPECODE"], (typecode, graphics) => new AttributeGroup { Key = typecode, Count = graphics.Count(), Sum = graphics.Select(g => (int)g.Attributes["DOW"]).Sum(), Graphics = graphics }).ToArray(); //END PIE CHART }
In the original example http://help.arcgis.com/en/webapi/sil...m#SpatialQueryI don't see the line
QueryDetailsDataGrid.ItemsSource = featureSet.Features;
I guess I just noticed the example is using a DataGrid and I'm using a FeatureDataGrid so i'm not sure if that makes a difference.
if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic)) QueryDetailsDataGrid.SelectedItems.Add(graphic);
That's likely the point. The selection of a FeatureDataGrid is automatically synchronized with the graphic selection. So you can simply remove these lines:
Code:
if (QueryDetailsDataGrid.ItemsSource != null && QueryDetailsDataGrid.ItemsSource.Cast<Graphic>().Contains(graphic))
QueryDetailsDataGrid.SelectedItems.Add(graphic);
That being said, I don't understand, how this code could have compiled if QueryDetailsDataGrid was a FeatureDataGrid
QueryDetailsDataGrid.SelectedItem = null; foreach (var graphic in attributeGroup.Graphics) { QueryDetailsDataGrid.SelectedItems.Add(graphic); graphic.Select(); }
foreach (var graphic in attributeGroup.Graphics) { graphic.Select(); }
NathalieNeagle
I have a simple police application that allows officers to spatial select and query some points (police calls).