0

I am new in C#, I was given a VB code to migrate in C#. I have done most of it but not able to populate data in COMBOBOX.

On clicking the dropdown button, Combobox is blank, on clicking the blank box it pops up with message ( please select from layer list) which it is suppose on not selecting from populated layer list.

namespace AddIndReferenceImagery_C
//CLASS BEGINS
{
    public class DEM : ESRI.ArcGIS.Desktop.AddIns.ComboBox
    {
        // * CONSTANT DEFINITIONS
        private const int MAXNUMBER = 22;
        private const string pPath = "P:\\declared path

        // * CONSTRUCTOR
        public void New()
        {
            // *constructor new calls the sub OnFocus
        OnFocus(false);
        }

        protected override void OnFocus(bool set)
        {

            IMxDocument pMxDoc = ArcMap.Document;
            loadComboBoxOn();                      
            base.OnFocus(set);
         }

        public void loadComboBoxOn()
        {
            Clear();

            String[]imageryArray = {layer name  };

            int index = 0;
            for (index = 0; index<=MAXNUMBER;index++)

            {
               Add(imageryArray[index]);
            }
          } // END loadComboBox()

        protected override void OnSelChange(int cookie)
        {
            IMxDocument pMxDoc = ArcMap.Document;
            IMap pMap = pMxDoc.FocusMap;
            IActiveView activeView = pMxDoc.ActiveView;
            IMap map = activeView.FocusMap;

            loadLayer(Value);
            pMxDoc.UpdateContents();
            OnFocus(true);
            base.OnSelChange(cookie);
        }
        private void loadLayer(string inLayer)
        {
            IMxDocument pMxDoc = ArcMap.Document;
            IMap pMap = pMxDoc.FocusMap;
           IActiveView activeView = pMxDoc.ActiveView;
           IMap map = activeView.FocusMap;

                      if (Value == "Add dem Layers..." || Value == "" || Value == " Image is not available at the time")
            {
                MessageBox.Show("Please select a layer from the layer list");
            }

            else
            {
                IGxLayer pGxLayer = new GxLayer();
                IGxFile pGxFile = pGxLayer as IGxFile;

               string pLayerName = pPath + inLayer;

                pGxFile.Path = pLayerName;
                 pMap.AddLayer(pGxLayer.Layer);
             //   MessageBox.Show("pLayerName after AddLayer");

                test_Spatial_Ref_Layer(pGxLayer);
                pGxLayer.Layer.Visible = true;
  • Thanks for replying, I added the ppath which was a typo and also have entered the layer names in LoadComboBoxOn() but no change, still I am unable to see the Layer Name populating in the combobox of ArcMap tool. – user75921 Jun 27 '16 at 15:19
1

One problem I see (which could just be how the code was copied into the question) is the const pPath quoted string is not properly formed (needs quotes front and back.)

Likely that was just a typo, and not the real source of the problem...

However, the loadComboBoxOn() appears to build an image array out of a list of layer names...but I don't see where that name variable is set. Please put a breakline in that proc and step through it to see that the ImageArray index is more than just 0...0 -- in other words make sure that the ImageArray has members, and interrogate those members in break mode.

Please report back the results, because I believe loadComboBoxOn() is not getting any layer names to add to the combo box on this line:

String[]imageryArray = {layer name  };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.