I have a query task that then populates a datagrid with the results. I'd like to be able to zoom to a particular feature when it's clicked on in the datagrid using the SelectionChanged event; I have it working with the results from a FindTask, using the findresult, but I can't quite figure out how to make it work with QueryTask and FeatureSet. Can anyone help? I've included the code below for the FindTask code, but I haven't been able to correctly alter it to work for the Query results.
private void FindResults_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Highlight the graphic feature associated with the selected row
DataGrid dataGrid = sender as DataGrid;
int selectedIndex = dataGrid.SelectedIndex;
if (selectedIndex > -1)
{
FindResult findResult = (FindResult)resultsDataGrid.SelectedItem;
Graphic graphic = findResult.Feature;
ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = findResult.Feature.Geometry.Extent;
ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
selectedFeatureExtent.XMin - 500,
selectedFeatureExtent.YMin - 500,
selectedFeatureExtent.XMax + 500,
selectedFeatureExtent.YMax + 500);
MapApplication.Current.Map.ZoomTo(displayExtent);
string StrGeometry = findResult.Feature.Geometry.GetType().ToString();
if (StrGeometry.Equals("ESRI.ArcGIS.Client.Geometry.MapPoint"))
{
graphic.Symbol = Circle;
}
if (StrGeometry.Equals("ESRI.ArcGIS.Client.Geometry.Polygon"))
{
graphic.Symbol = Fill;
}
if (StrGeometry.Equals("ESRI.ArcGIS.Client.Geometry.Polyline"))
{
graphic.Symbol = YellowLine;
}
GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
graphicsLayer.Graphics.Add(graphic);
}
}