Hi, I'm trying to make a datagrid that autopopulates with a handful of counties. I believe the new featuredatagrid and the querytask would be the best way to do this so I can keep the parameters dynamic as to which counties are in the datagrid. I have two questions about this, how would I go about only returning specific, pre-set results through the querytask (is it through use of the "Where" public property or "ObjectID")? And my second question is, how would I pre-set the featuredatagrid to autozoom to selected Item instead of autozoom to selected being toggle off by default. I can't seem to find that property setter anywhere in the API reference.Thanks for any help.
private static Graphic GetGraphicSibling(object item) { if (item != null) { MethodInfo mi = item.GetType().GetMethod("GetGraphicSibling"); if (mi != null) return mi.Invoke(item, null) as Graphic; } return null; } private void BookmarksDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (var item in e.AddedItems) { var g = GetGraphicSibling(item); g.Select(); TabletMap.ZoomTo(g.Geometry); } foreach (var item in e.RemovedItems) { var g = GetGraphicSibling(item); g.UnSelect(); } }
private void BookmarksDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { object obj = e.AddedItems[0]; //This bit of trickery is from a post that Jennifer made on the forum to convert the SelectedItem to a graphic using reflection MethodInfo methodInfo = obj.GetType().GetMethod("GetGraphicSibling"); if (methodInfo == null) return; Graphic g = methodInfo.Invoke(obj, null) as Graphic; foreach (Graphic g in e.AddedItems) { g.Select(); TabletMap.ZoomTo(g.Geometry); } foreach (Graphic g in e.RemovedItems) g.UnSelect(); }
object obj = e.AddedItems[0]; //This bit of trickery is from a post that Jennifer made on the forum to convert the SelectedItem to a graphic using reflection MethodInfo methodInfo = obj.GetType().GetMethod("GetGraphicSibling"); if ( methodInfo == null ) return; Graphic g = methodInfo.Invoke(obj, null) as Graphic;
private void RunWestTexasCountyQuery() { ClearAllGraphics(); GraphicsLayer searchGraphicsLayer = TabletMap.Layers["SearchGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { ReturnGeometry = true, OutSpatialReference = TabletMap.SpatialReference, Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')" }; query.OutFields.Add("CNAME"); QueryTask queryTask = new QueryTask("<serviceURL>"); queryTask.ExecuteCompleted += (s, a) => { foreach (Graphic g in a.FeatureSet.Features) searchGraphicsLayer.Graphics.Add(g); }; queryTask.ExecuteAsync(query); queryTask.Failed += QueryTask_Failed; } private void QueryTask_Failed(object sender, TaskFailedEventArgs args) { MessageBox.Show("Query execute error: " + args.Error); } private void BookmarksDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (ESRI.ArcGIS.Client.Graphic g in e.AddedItems) { g.Select(); TabletMap.ZoomTo(g.Geometry); } foreach (ESRI.ArcGIS.Client.Graphic g in e.RemovedItems) g.UnSelect(); }
private void CountiesDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { foreach (Graphic g in e.AddedItems) { g.Select(); TabletMap.ZoomTo(g.Geometry); } foreach (Graphic g in e.RemovedItems) g.UnSelect(); }
Where = string.Format("CNAME LIKE '%{0}%'", FindText.Text),
CNAME = 'CULBERSON'
CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')
Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"
private void RunCountyQuery() { ClearAllGraphics(); GraphicsLayer searchGraphicsLayer = TabletMap.Layers["SearchGraphicsLayer"] as GraphicsLayer; int[] ObjIDs = new int[6]{55,122,151,195,238,248}; ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { ReturnGeometry = true, OutSpatialReference = TabletMap.SpatialReference, ObjectIDs = ObjIDs, }; query.OutFields.Add("CNAME"); QueryTask queryTask = new QueryTask("<serverURL>"); queryTask.ExecuteCompleted += (s, a) => { foreach (Graphic g in a.FeatureSet.Features) searchGraphicsLayer.Graphics.Add(g); }; queryTask.ExecuteAsync(query); }
Where = "CNAME = 'CULBERSON'"
See if this works Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"
Where = string.Format("CNAME IN ('CULBERSON','JEFF DAVIS','REEVES','WARD','WINKLER')"),
private void RunCountyQuery() { ClearAllGraphics(); GraphicsLayer searchGraphicsLayer = TabletMap.Layers["SearchGraphicsLayer"] as GraphicsLayer; ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { ReturnGeometry = true, OutSpatialReference = TabletMap.SpatialReference, Where = "CNAME IN (CULBERSON, JEFF DAVIS, LOVING, REEVES, WARD, WINKLER)" }; query.OutFields.Add("CNAME"); QueryTask queryTask = new QueryTask("<mapserviceURL>"); queryTask.ExecuteCompleted += (s, a) => { foreach (Graphic g in a.FeatureSet.Features) searchGraphicsLayer.Graphics.Add(g); }; queryTask.ExecuteAsync(query); }
The FeatureDataGrid binds to a GraphicsLayer so there are two approaches you can use. Either using a FeatureLayer (which inherits from GraphicsLayer) or use a GraphicsLayer and add the Graphics objects in code. Personally I think if possible the FeatureLayer simplifies things over running a Query and then adding Graphics to the GraphicsLayer, but neither way is more correct than the other.As for using ObjectId property or the Where clause it is really another case of there is no best answer. I think in general the Where is more standard because the ObjectID could potentially change (like if for some reason data was reloaded into a Feature Class). If there is not some attribute that is being used (e.g., all counties with population over 1,000,000 or counties with the best BBQ 🙂 - you are in TX right?) you can always use a SQL In clause on the name (Where = "Name In (CountyA, CountyB,...)")This thread may help with how to go about zooming to the location when the user clicks on the item in the FeatureDataGrid.http://forums.arcgis.com/threads/58076-zoom-to-points?p=201782#post201782Hope that helps
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.