Last night a student from my Udemy course about writing Python AddIns asked for:
some tips for using a combo box to filter another combo box. What I am trying to do is use a combo box to select my [feature class], which I've managed to do. Once that combo box is selected, I want the second box to show all the fields in that [feature class], which I can then go ahead and select to perform further analysis on.
I think the key to doing this may be found in code from @sur's answer (with help from Freddie Gibson of Esri) to Dynamically adding items into one python addin Combobox from another?:
import arcpy
import pythonaddins
class ComboBoxClass1(object):
"""Implementation for TestCombo_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["cb1item1", "cb1item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
ComboBoxClass1._hook=self
def onSelChange(self, selection):
pass
class ComboBoxClass2(object):
"""Implementation for TestCombo_addin.combobox_1 (ComboBox)"""
def __init__(self):
self.items = ["cb2item1", "cb2item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
ComboBoxClass1._hook.items.append(selection)
but how do I use the _hook
property of a ComboBoxClass to achieve what my student has asked for?