Solved! Go to Solution.
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.
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.
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#post201782
Hope that helps
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); }
Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"
See if this worksWhere = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"
Where = string.Format("CNAME IN ('CULBERSON','JEFF DAVIS','REEVES','WARD','WINKLER')"),
Where = "CNAME = 'CULBERSON'"
CNAME = 'CULBERSON'through the query page in the services browser under the Where search textbox,as well as,
CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER'). However, when I input it into my applications code as
Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')", no results are given. I believe it might be a problem on the way we write it on the apps side. I'll keep tinkering with it, but if you think of anything please let me know.
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); }