Select to view content in your preferred language

Problem to Access fields from the feature layer

515
1
08-29-2010 05:11 PM
VikramS
Frequent Contributor
This is the xaml code where i am assigning the layer which is to be my featurelayer which has been highlighted with maroon color . And below that is my code behind ..

I am getting error when i try to access the field names of the layer . I get 0 fields . Can anybody help out with this prob .. Thanks




<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<esriSymbols:SimpleFillSymbol x:Name="MyMarkerSymbol" Fill="Chocolate" BorderThickness="2" BorderBrush="Aqua" />
</Grid.Resources>
<esri:Map Background="White" Name="Map1">
<esri:Map.Layers>
<esri:ArcGISDynamicMapServiceLayer ID="mymap" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapSe..." Initialized="ArcGISTiledMapServiceLayer_Initialized"/>
  <esri:FeatureLayer ID="city" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapSe..." FeatureSymbol="{StaticResource MyMarkerSymbol}" Initialized="FeatureLayer_Initialized"/>
</esri:Map.Layers>
</esri:Map>
<StackPanel Orientation="Horizontal">
<ComboBox Name="field" Width="119" Height="50"/>
</StackPanel>
</Grid>


Code Behind code

Dim f As ESRI.ArcGIS.Client.Layer = CType(Map1.Layers("city"), ESRI.ArcGIS.Client.Layer)
Dim a As ESRI.ArcGIS.Client.FeatureLayer = CType(f, ESRI.ArcGIS.Client.FeatureLayer)
Dim i As Integer = -1
If Not a.LayerInfo Is Nothing Then
For i = 0 To a.LayerInfo.Fields.Count - 1
field.Items.Add(a.LayerInfo.Fields(i).Type)
Next
End If
End If
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
Your code should work if it's executed after the layer has been initialized (e.g in FeatureLayer_Initialized)

When is executed your code behind?

0 Kudos