Select to view content in your preferred language

FeatureDataGrid Binding Issue

1005
11
11-04-2010 01:37 PM
KeithGanzenmuller
Frequent Contributor
Having a bear of a time figuring this one out so I am going to post some of the code to see if there is something obvious I am doing wrong. In theory this should be fairly straight forward following the online samples.
Query for some features, display the selected graphics and populate the feature datagrid.

Here is the beginning of some code defining and executing a query task part way down in a Sub:

myGraphicsLayer.ClearGraphics()
SelectionText.Text = _toolBar

Dim queryTask As New Tasks.QueryTask("http://sql2k5/ArcGIS/rest/services/CityBasic/MapServer/8")
AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
AddHandler queryTask.Failed, AddressOf QueryTask_Failed

'Code Section 1
Dim resultFeaturesBinding As New Binding("LastResult.Features")
resultFeaturesBinding.Source = queryTask
featureGrid1.SetBinding(DataGrid.ItemsSourceProperty, resultFeaturesBinding)
'End Section 1

Dim query As Query = New ESRI.ArcGIS.Client.Tasks.Query()

' Specify fields to return from query
query.OutFields.AddRange(New String() {"SHAPE", "PARCEL", "PRPDNO", "PRPDST", "OWNERS"})
query.Geometry = args.Geometry
query.ReturnGeometry = True
queryTask.ExecuteAsync(query)
End Sub

'NEW SUB
Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
MyDrawObject.IsEnabled = True


Dim featureSet As FeatureSet = args.FeatureSet


If featureSet Is Nothing OrElse featureSet.Features.Count < 1 Then
MessageBox.Show("No features returned from query")
Return
End If

For Each feature As Graphic In featureSet.Features
feature.Symbol = TryCast(LayoutRoot.Resources("PolyFillSymbol"), Symbol)

myGraphicsLayer.Graphics.Add(feature)
Next feature


'Code Section 2 '

featureGrid1.ItemsSource = featureSet.Features
'End Section 2

_toolBar = " "


End Sub

So here is the problem, if I include the binding code in Section1, then I get an error in my for each loop at "myGraphicsLayer.Graphics.Add(feature)", inside the error details it mentions System.Reflection.TargetException: Object does not match target type. If comment out the binding code, my graphics add to map but no info into the featuredatagrid. If I add the line at Section 2 "featureGrid1.ItemsSource = featureSet.Features" & comment out Section 1, I get the graphics and the featuredatagrid info, but it crashes if I try to use Zoom to Select.
The real kicker, if I comment out both Section 1 & 2, I get the graphics and the grid shows lines but they are blank. If I select a blank line, its shows the line selected and will zoom to selected.

Thanks,
Keith
0 Kudos
11 Replies
AliMirzabeigi
Emerging Contributor
The only thing that we can think of would be because of the "DisplayField" property of your layer. For example, the following layer has its "DisplayField" set to "description" and if your FeatureLayer's OutFields property has not been set then the "description" attribute would be the only column displayed in your datagrid:
http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/FeatureServer/0
0 Kudos
KeithGanzenmuller
Frequent Contributor
I sort of have it working now, but not sure exactly why.
If I put OutFields="*" in the XAML, I get the column headings and correct behavior (selection highlights the parcels, I can step through the features) but no attributes in the rows.
If I put  query.OutFields.AddRange(New String() {"*"}) in the code, but don't but OutFields="*"  in XAML, I get nothing in the datagrid except it indicates the correct number of selected features.

If I have both OutFields="*"  in XAML and query.OutFields.AddRange(New String() {"*"})  in code, I get all the fields, column headers and correct behavior.

So, basically it works, just not sure why.
0 Kudos