-1

Using ArcGIS Python addin I need to get the Index of selected item from Combobox on change

I already tried

   def onSelChange(self, text):  
        global selectedIndex
        selectedIndex = selection.current() 

in following code

class ComboBoxClass4(object):  
    """Implementation for MTR_addin.combobox (ComboBox)"""  
    def __init__(self):  
        self.value = "S"    
        self.items = ("A", "B", "C", "D", "E")   
        self.editable = True  
        self.enabled = True  
        self.dropdownWidth = 'WWW'  
        self.width = 'WWW'  
    def onSelChange(self, selection):  
        global selectedIndex
        selectedIndex = selection.current()    
    def onEditChange(self, text):  
        pass
    def onFocus(self, focused):  
        pass  
    def onEnter(self):  
        pass  
    def refresh(self):  
        pass 

but it is not working and I am getting this error

selection.current() AttributeError: 'str' object has no attribute 'current'

0

If you read the help page in ArcMap on Combo Box Class, the method onSelChange says

Occurs each time a new selection is made in the combo box. selection specifies the value selected by the user.

Your combo box contains the text values "A", "B", "C", "D", "E". So it will be one of those values. current() is not a method for a string value. So simply remove it and just have selection.

  • Unsure why the downvotes - would any downvoters like to comment why? selection holds the selected value from the combo-box so is all that is needed to return that value. – Midavalo May 26 '17 at 18:45

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.