Select to view content in your preferred language

Getting error while adding child layer to GroupLayer in code behind.

1145
3
12-05-2011 03:15 AM
SanajyJadhav
Deactivated User
Hello,

I am adding the child layer to the Group layer in the code behind (adding them in XAML is not feasible for me)and getting the exception "Value does not fall within the expected range".

My code is as below.


//create new group layer & set ID
GroupLayer siteIntentGrLyr = new GroupLayer();
siteIntentGrLyr.ID = "Site Intent Group Layer";

//access indidual feature layers from the collection & add them to the siteIntentGrLyr
Layer plantFeatLyr = featLyrList.FirstOrDefault(x => x.LayerInfo.Name == "Plant");
Layer otherFeatPointFeatLyr = featLyrList.FirstOrDefault(x => x.LayerInfo.Name == "Other_Features_Point");
Layer Other_Feature_LineFeatLyr = featLyrList.FirstOrDefault(x => x.LayerInfo.Name == "Other_Features_Line");
Layer Other_Feature_BoundaryFeatLyr = featLyrList.FirstOrDefault(x => x.LayerInfo.Name == "Other_Feature_Boundary");

//add child feature layers to the group layer
siteIntentGrLyr.ChildLayers.Add(plantFeatLyr); //on this very first line, I get error.
siteIntentGrLyr.ChildLayers.Add(otherFeatPointFeatLyr);
siteIntentGrLyr.ChildLayers.Add(Other_Feature_LineFeatLyr);
siteIntentGrLyr.ChildLayers.Add(Other_Feature_BoundaryFeatLyr); 


I would appreciate any help on this issue.Thanks in advance.
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor

I am adding the child layer to the Group layer in the code behind (adding them in XAML is not feasible for me)and getting the exception "Value does not fall within the expected range".



You might get this error when adding twice the same layer in the map.

If your feature layer is already in the map, you have to remove it before adding it in the group layer : i.e MyMap.Layers.Remove(plantFeatLyr);
0 Kudos
SanajyJadhav
Deactivated User
Thanks Dominique for the reply.

I am not sure but I might be adding the layer twice as you mentioned.I would look into it and and give a try.

Thanks once again.
0 Kudos
SanajyJadhav
Deactivated User
It worked. Thanks for the help Domnique, appreciate it.

My thought is this should be mentioned in class documentation for GroupLayer, otherwise it is very confusing. Because adding a layer to the map and to the GroupLayer are two different things in my opinion.

Cheers,
0 Kudos