Select to view content in your preferred language

Questions about featuredatagrip and new querytask

1942
16
Jump to solution
07-10-2012 07:26 AM
JaredWhite
Regular Contributor
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.
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Alum
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
Thanks,
-Joe

View solution in original post

0 Kudos
16 Replies
JoeHershman
MVP Alum
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
Thanks,
-Joe
0 Kudos
JaredWhite
Regular Contributor
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


Thanks for the answer Joe. You've been helpful as always.
As for the zoomto questions, the new featuredatagrid, which I've chosen to use because the featurelayer simplifies things for me, has a toggle in the options to automatically zoom to any point selected (http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#OrderByFieldQuery), but if I add the zoomto code manually (like we had to before the featuredatagrid was in the toolkit), it makes the code wonky and sometimes throws exceptions. I was hoping to see if anyone that had worked directly on the new toolkit could tell me if the option to have it zoomto automatically could be set as the default or not. I've checked through the API reference library and can find absolutely no reference to it, so my inclination is no without modifying the source code, but I just wanted to see.
Thanks again though Joe.
0 Kudos
JoeHershman
MVP Alum
My bad, I actually had not seen the updated FeatureDataGrid.  Surprised no one though to expose that property, but looking at the code does not seem there would be anyway without making your own modified FeatureDataGrid
Thanks,
-Joe
0 Kudos
JaredWhite
Regular Contributor
Also, I still seem to be having trouble with my query working properly. Do you mind taking a look at my code and telling me what I've done wrong? As stated earlier, my desired result is a list of these six counties showing up in the FeatureDataGrid, yet for some reason, it isn't returning any results. In the datatables, the column name is CNAME and the six counties I want to display are listed in the Where SQL IN clause below.

        
        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);
        }


Also, do you know how to make the resulting featureset to only be sent to one featuredatagrid, instead of all of them?
0 Kudos
JoeHershman
MVP Alum
See if this works


    Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"

Thanks,
-Joe
0 Kudos
JaredWhite
Regular Contributor
See if this works


    Where = "CNAME IN ('CULBERSON', 'JEFF DAVIS', 'LOVING', 'REEVES', 'WARD', 'WINKLER')"



Still nothing, I also tried

                Where = string.Format("CNAME IN ('CULBERSON','JEFF DAVIS','REEVES','WARD','WINKLER')"),

In case it had to be wrapped in a Format like the example in the samples.
0 Kudos
JoeHershman
MVP Alum
Have you tried a simple query from your browser just to see if that will return any results?  Something like this but maybe play around with it in your browser and see if you get any return values


    
 Where = "CNAME = 'CULBERSON'"



Good Luck
Thanks,
-Joe
0 Kudos
JaredWhite
Regular Contributor
It works when I query
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.

However, the problem could lie with the execution of another part of the query code, though I don't see it. This does not work either.
  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);
        }
0 Kudos
JoeHershman
MVP Alum
I would put in a Failed handler and see if something comes back.  Everything looks good, the only thing I can think is that something is missing in your Url, the Failed response might give a helpful response.  You do have the proper LayerId in your Url?  Also you can download a tool called Fiddler if you don't have it, this will show you the rest calls and you can use it to compare what comes out of your code to what comes out of the browser.

Good Luck
Thanks,
-Joe
0 Kudos