Binding Query Result To FeatureDataGrid

3244
12
07-26-2011 01:24 AM
ManojrajTeli
Occasional Contributor II
I am trying to bind the query result returned from by query to the FeatureDataGrid but instead of attributes the geometry of the result is getting bound to Feature datagrid.Please suggest the code to bind attributes to FeatureDataGrid.Thank you in advance.
0 Kudos
12 Replies
JenniferNery
Esri Regular Contributor
FeatureDataGrid will display fields that are in your graphic.Attributes. If your FeatureDataGrid.GraphicsLayer contain the results of your query and you have specified query.OutFields, these should be the same fields contained in the FeatureDataGrid.

Your FeatureDataGrid.Map and GraphicsLayer need to be set, similar to this:
        <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid" 
    Map="{Binding ElementName=MyMap}"
    GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayerID]}" />
0 Kudos
ManojrajTeli
Occasional Contributor II
Oh thank you but this is during initialization that i have done already i want the part QueryTask_ExecutionCompleted event.
This is the Piece of Code what i have done.
Void queryTask_ExecuteCompleted(Object sender,ESRI.ArcGIS.Client.Task.QueryEventArgs e)
{
          FeatureSet featureset=e.FeatureSet;
          if(featureset != null && featureSET.Feature.Count>0)
          {
                   MyDataGrid.ItemsSource = featureSet.Features;//Here the attributed I have to bind
                                                                                   //Geometry is getting binded
           }
}
Suggest some way to bind attribute from feature set to FeatureDataGrid
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The ItemsSource of your FeatureDataGrid must reference the graphics instance that are inside the layer.
So instead of setting the ItemsSource directly to the result of the query, you have to project the query result in order to get graphics instances in the feature layer (by using the objectID).
There is a sample in this thread : http://forums.arcgis.com/threads/18708-Problem-selecting-features-from-a-Feature-Layer
0 Kudos
ManojrajTeli
Occasional Contributor II
Can please elaborate ...I am new at this and i tried those codes and not working and i want to show all the fields in feature datagrid depending on records selected by query and result returned...Its urgent.Thanks in advance.
0 Kudos
JenniferNery
Esri Regular Contributor
Actually, you should not be setting FeatureDataGrid.ItemsSource property.

As long as FeatureDataGrid.Map and GraphicsLayer are set. All you have to do in the Query.ExecuteCompleted event handler is add the results to your GraphicsLayer.Graphics.
0 Kudos
ManojrajTeli
Occasional Contributor II
I am directlly fetching the Featuredatagrid from query on featureservice and i can see geometry,map tip etc columns but i don't know how to bind only features columns from query result.If you have code then please share. thanks its urgent.Thank you in advance.
0 Kudos
JenniferNery
Esri Regular Contributor
Code is in post#2 This is all the Binding you will need for FeatureDataGrid.

This SDK sample shows how you can add results as graphic to your GraphicsLayer (see code-behind QueryTask_ExecuteCompleted):
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery
0 Kudos
EzequiasRodrigues_da_Rocha
New Contributor III
Hi,

Have someone solve the problem of showing the attribute table yet? Actually I do not have fixed attribute columns. I just want to display the attribute table of one layer with all values as I can see in ArcMap, but in my case I want to display using Silverlight.

Here is the code that retrieves the FeatureSelection:

QueryTask queryTask = new QueryTask(url);
queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryTask_ExecuteCompleted);

Query query = new Query();
query.ReturnGeometry = true;

// Use textbox text as query condition.
query.Where = "1=1";
query.OutFields.Add("*");
queryTask.ExecuteAsync(query);

And the population I was trying to make:

void queryTask_ExecuteCompleted(object sender, QueryEventArgs e)
{
attribWidget.featureDataGrid1.Map = this.MapControl;
attribWidget.featureDataGrid1.ItemsSource = e.FeatureSet.Features;
}

But I have no success neither with DataGrid nor FeatureDataGrid

ps: I don't want to make any previous selection on the map, so I don't need a graphic layer. I just want to display attributes on FeatureDataGrid
0 Kudos
EzequiasRodrigues_da_Rocha
New Contributor III
Code is in post#2 This is all the Binding you will need for FeatureDataGrid.

This SDK sample shows how you can add results as graphic to your GraphicsLayer (see code-behind QueryTask_ExecuteCompleted):
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery


Is it possible to bind without making a spatial selection? I just want to bind the attribute table of my layer.

Any suggestion will be welcomed.

Regards
Ezequias Rocha
0 Kudos