Select to view content in your preferred language

binding feature layer to Datagrid Row

3189
7
07-15-2011 11:05 AM
suharthachowdhury
Emerging Contributor
Hi,

I have a feature layer cosuming a map service and a Datagrid which is bound to a domain data source. Executing a Linq query populates the datagrid. Now I want to bind this datagrid to my feature layer so that clicking on the map feature will highlight corresponding datagrid row. How can I do this? I have one datagrid field that can tie the datagrid with a corresponding feature layer attribute. any helpful link/ suggestion will be much appreciated.

Thanks for helping me.
Suhartha
0 Kudos
7 Replies
JenniferNery
Esri Regular Contributor
You can look at the XAML code in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords to bind to the attributes.

You can set ItemsSource in code or in XAML, I believe it is something like this:
ItemsSource="{Binding Graphics}" DataContext="{Binding ElementName=MyMap, Path=Layers[MyLayerId]}".

If you are using FeatureDataGrid, this is a good example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid
0 Kudos
suharthachowdhury
Emerging Contributor
You can look at the XAML code in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords to bind to the attributes.

You can set ItemsSource in code or in XAML, I believe it is something like this:
ItemsSource="{Binding Graphics}" DataContext="{Binding ElementName=MyMap, Path=Layers[MyLayerId]}".

If you are using FeatureDataGrid, this is a good example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid



Hi Jennifer,

Thanks a lot for your reply. sorry for the delay. I need to make myself clearer: my datagrid is already bound to a domain data source to fetch data from a SQL table:
<sdk:  DataGrid ItemsSource="{Binding ElementName=view_KMDomainDataSource, Path=Data}" x:Name="view_KMDataGrid" ...>

In this case, how can I bind the datagrid to the map layer?? So the scenario is- the datagrid is populated with the query result. Also the feature layer has feature graphics that are related to the query. Now clicking on a feature shoould take me to corresponding datagrid row. Please help and any suggestion will be appreciated.

Thanks.
Suhartha
0 Kudos
JenniferNery
Esri Regular Contributor
If each row corresponds to a graphic, you will have access to the graphic.Attributes.  I suggest you look into the Related Tables sample, specifically this event handler in code-behind: SelectedWellsTreeView_SelectedItemChanged
0 Kudos
JianChen
Regular Contributor
If each row corresponds to a graphic, you will have access to the graphic.Attributes.  I suggest you look into the Related Tables sample, specifically this event handler in code-behind: SelectedWellsTreeView_SelectedItemChanged


Hey Jennifer, I tried to set binding to a feature datagrid at run-time through code-behind. I took your suggestion but the binding set seems not working because the datagrid disapear. Initially I bind it with a feature layer but at run time I need re-set the binding to other layers. Below is my code:

           //binding feature datagrid to target layer
            Binding bMap = new Binding("bMap");
            bMap.Source = MyMap;

            Binding bLayer = new Binding("bLayer");
            bLayer.Source = MyMap.Layers["RegionLayer"];

            MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, bMap);
            MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, bLayer);


Initial setting for feature datagrid in XAML:

<esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"
  Map="{Binding ElementName=MyMap}" 
                GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[PPP_StateLayer]}" />


Any idea what's wrong?
0 Kudos
JianChen
Regular Contributor
You can look at the XAML code in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords to bind to the attributes.

You can set ItemsSource in code or in XAML, I believe it is something like this:
ItemsSource="{Binding Graphics}" DataContext="{Binding ElementName=MyMap, Path=Layers[MyLayerId]}".

If you are using FeatureDataGrid, this is a good example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid


Hey Jennifer, do you have any sample to selectively bind GraphicsLayer to FeatureDataGrid in XAML. The sample you mentioned here bind all fields to the FeatureDataGrid; I just need to select several of them to bind instead. Thanks.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Hey Jennifer, I tried to set binding to a feature datagrid at run-time through code-behind. I took your suggestion but the binding set seems not working because the datagrid disapear. Initially I bind it with a feature layer but at run time I need re-set the binding to other layers. Below is my code:

           //binding feature datagrid to target layer
            Binding bMap = new Binding("bMap");
            bMap.Source = MyMap;

            Binding bLayer = new Binding("bLayer");
            bLayer.Source = MyMap.Layers["RegionLayer"];

            MyDataGrid.SetBinding(FeatureDataGrid.MapProperty, bMap);
            MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, bLayer);


Initial setting for feature datagrid in XAML:

<esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"
        Map="{Binding ElementName=MyMap}" 
                GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[PPP_StateLayer]}" />


Any idea what's wrong?


I don't think you need a binding. You can directly set the Map and GraphicsLayer properties:
MyDataGrid.Map = MyMap;
MyDataGrid.GraphicsLayer =  MyMap.Layers["RegionLayer"];

Easier, no?:o

Sidenote : when you create a binding by code, the string in the binding constructor is supposed to be the 'Path'.
So your code:
 Binding bMap = new Binding("bMap");
Binding bLayer = new Binding("bLayer");

should be:
 Binding bMap = new Binding("");
Binding bLayer = new Binding("");
bLayer.Source = MyMap.Layers["RegionLayer"];



or

Binding bLayer = new Binding("Layers[RegionLayer]");
bLayer.Source = MyMap;
0 Kudos
JianChen
Regular Contributor
Hi Dominique, Thanks for your suggestion! I'll try it this afternoon. How about any suggestion on selectively bind fields to FeatureDataGrid at initialization in XAML as I asked above? I searched a little bit but couldn't find a good example to do so. Any suggestion will be appreciated.
0 Kudos