Select to view content in your preferred language

FeatureLayer data context

1271
9
02-16-2011 06:18 AM
DonFreeman
Emerging Contributor
I noticed that the FeatureDataGrid has a property for DataContext. Does this suggest that the FeatureLayer upon which the FeatureDataGrid also has a DataContext? I would like to be able to work with the FeatureLayer's attribute table as if it were a free standing table in the database (export it to excel for example). If the answer to this is yes, how would one go about establishing a link to the table?

Thanks
0 Kudos
9 Replies
AliMirzabeigi
Emerging Contributor
FeatureLayer does not DataContext property as it is not of type FrameworkElement. Unfortunately, there is no such attribute table that you are looking for in feature layers and you would need to either iterate through the Graphic objects in your layer or FeatureDataGrid's ItemsSource in order to retrieve items attributes.
0 Kudos
DonFreeman
Emerging Contributor
Ali -
The FeatureDataGrid is based on the FeatureLayer. Does it have a DataContext (intellisense suggests that it does) and can it be used to extract the attribute table?
Thanks
0 Kudos
AliMirzabeigi
Emerging Contributor
FeatureDataGrid DataContext property does not have any data in regards to the attributes table. You need to extract the attributes from the graphic collection of your FeatureLayer or the ItemsSource in FeatureDataGrid like mentioned in post #2.
Hope this helps.
0 Kudos
DonFreeman
Emerging Contributor
OK Ali, here is my end game. The datagrid and the map are side by side on the page. There are no features selected on the map. The user selects a record in the datagrid. I want to display the corresponding feature on the map as the selected feature. How can I do that? Iterating through the graphics in the layer will do no good because none of them are selected yet. Therefore I need to extract the KeyID from the grid. Then iterate through the graphics and tag the right one as selected.
0 Kudos
AliMirzabeigi
Emerging Contributor
Haven't you set FeatureDataGrid's "Map" property? If you did, then you wouldn't need to perform the selection on your layer as FeatureDataGrid automatically selects the corresponding Graphic of the selected row on your map.
0 Kudos
DonFreeman
Emerging Contributor
Thanks Ali. Problem solved. You are correct. The grid selection is automatically shown on the map. Plus I found the Export to Excel routine I had previously used with the regular silverlight datagrid also works with the featuredatagrid.
0 Kudos
JoannaLaroussi
Emerging Contributor
Thanks Ali. Problem solved. You are correct. The grid selection is automatically shown on the map. Plus I found the Export to Excel routine I had previously used with the regular silverlight datagrid also works with the featuredatagrid.


I am looking for the way to export data from Data Grid to Excel. You suggested in your post that you have a routine how to do it. Could you explain me how to approach this issue?
0 Kudos
DonFreeman
Emerging Contributor
I am looking for the way to export data from Data Grid to Excel. You suggested in your post that you have a routine how to do it. Could you explain me how to approach this issue?


Check this out. It works fine for me.
http://www.codeproject.com/KB/silverlight/SilverlightDataGridExport.aspx
0 Kudos
JoannaLaroussi
Emerging Contributor
Thank you!
0 Kudos