Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've got an add-in with a combo box and want to refresh the list in the combo box after an event in one of the other tools in the same add-in toolbar.

Can I call the combo box somehow to refresh it outside of the object's onSelChange event?

share|improve this question
    
Can I see your code solution please, I have the same problem. I need to link a couple of combos. thank you and best regards! –  user17971 May 9 '13 at 0:45
    
Welcome to GIS-SE! One thing though - this would make a good Comment on the previous Answer but is itself not an Answer to the Question. –  PolyGeo May 9 '13 at 1:23

1 Answer 1

up vote 2 down vote accepted

Finally managed to sort this one out. I managed to do that by adding a method in the combo box class, initiated them in the button class (where I wanted to refresh the combo box from) and then called the methods from within the button class.

import arcpy
import pythonaddins

cboSetup1 = None
cboSetup2 = None

class btn1(object):
    """Implementation for Class_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        combo1 = cbobox1()
        combo1.btnPopulate()
        combo2 = cbobox2()
        combo2.btnPopulate()

class cbobox1(object): 
    """Implementation for Class_addin.combobox (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onFocus(self, focused):
        self.items = cboSetup1
    def btnPopulate(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        self.items = []
    for layer in arcpy.mapping.ListLayers(mxd):
        self.items.append(layer.name)
    global cboSetup1
        cboSetup1 = self.items

class cbobox2(object):
    """Implementation for Class_addin.combobox_1 (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onFocus(self, focused):
        self.items = cboSetup2
    def btnPopulate(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        self.items = []
    for layer in arcpy.mapping.ListLayers(mxd):
        self.items.append(layer.name)
    global cboSetup2
        cboSetup2 = self.items
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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