AnsweredAssumed Answered

Populating a combobox with the fields of a featurelayer nested in a grouplayer

Question asked by tauhid37 on Oct 16, 2013
Latest reply on Oct 18, 2013 by tauhid37
Hello everyone,
I don't get a clue how to resolve a problem. I have a form which have two combobox and a textbox and a button for search option. when I run the app in combobox1 the LAYER names of TOC will populate, when I select a layer in combobox1 then in combobox2 the fields of that layer will populate. but it is not happening in case of GroupLayer the combobox1 works perfect but combobox2 got messy it populates the field name but populates 6 times and in case of FeatureLayer it give an error.following is my code, Please help me-
private void cmbShape_SelectedIndexChanged(object sender, EventArgs e)         {             combobox2.SelectedIndex = -1;                          combobox2.Items.Clear();                          string shape = combobox1.Text;                 IApplication pApplication = ArcMap.Application;             IMxDocument pMxDoc = (IMxDocument)pApplication.Document;             IActiveView pActiveView = pMxDoc.ActiveView;             IMap pMap = pMxDoc.FocusMap;                 IFeatureLayer pFeatLayer = null;             IFeatureClass pFeatClass = null;             IFields pFields = null;             IField pField;             string FieldName;              IEnumLayer pEnumLayer = pMap.get_Layers(null, true);             pEnumLayer.Reset();             ILayer pLayer = pEnumLayer.Next();              while (pLayer != null)             {                 if (pLayer is ICompositeLayer)                 {                                          ICompositeLayer pComLayer = (ICompositeLayer)pLayer;                     int i = pComLayer.Count;                                          for (int j = 0; (j < i); j++)                     {                         if (pComLayer.get_Layer(j).Name == shape)                         {                             pFeatLayer = (IGeoFeatureLayer)pComLayer.get_Layer(j);                         }                     }                     pFeatClass = pFeatLayer.FeatureClass;                     pFields = pFeatClass.Fields;                     int k = pFields.FieldCount;                                          for (int y = 0; (y < k); y++)                     {                         pField = pFields.get_Field(y);                         FieldName = pField.Name;                         combobox2.Items.Add(FieldName);                                             }                 }                 else if(pLayer is IFeatureLayer)                 {                     int l = pMap.LayerCount;                     for (int u = 0; (u < l); u++)                     {                         if (pMap.get_Layer(u).Name == shape)                         {                             pFeatLayer = (IGeoFeatureLayer)pMap.get_Layer(u);                         }                     }                     pFeatClass = pFeatLayer.FeatureClass;                     pFields = pFeatClass.Fields;                     int k = pFields.FieldCount;                      for (int f = 0; (f < k); f++)                     {                         pField = pFields.get_Field(f);                         FieldName = pField.Name;                         combobox2.Items.Add(FieldName);                                              }                 }                 pLayer = pEnumLayer.Next();             }                                  }

Outcomes