I have a layer of districts. Each district belongs to a different state. I want to write code that once you choose a state in the 2end combobox, you can only see districts from that certain state in the 3rd combobox. I wrote the following code:
def myFunction(self, layer, featureSet2): Feature_list3 =  del Feature_list3[0:len(Feature_list3)] indx = self.dlg.comboBox.currentIndex() Data = featureSet2[indx] layer.removeSelection() # Fill 3rd combobox self.dlg.comboBox_3.clear() for feature in layer.getFeatures(): name = feature["NAME_2"] if Data==feature["TYPE_2"]: #print (Data) Feature_list3.append(name) self.dlg.comboBox_3.addItems(Feature_list3) # Fill 3rd combobox def run(self): """Run method that performs all the real work""" layer = iface.addVectorLayer("C:/Users/carmel.han/Documents/QGIS/qgis_sample_data/shapefiles/regions.shp", "regions", "ogr") Feature_list =  Feature_list2 =  selection =  #Fill 1st combobox self.dlg.comboBox.clear() for feature in layer.getFeatures(): name = feature["name_1"] Feature_list.append(name) featureSet = set(Feature_list) self.dlg.comboBox.addItems(featureSet) # Fill 1st combobox # Fill 2end combobox Feature_list2 =  self.dlg.comboBox_2.clear() for feature in layer.getFeatures(): name = feature["TYPE_2"] Feature_list2.append(name) featureSet2 = set(Feature_list2) self.dlg.comboBox_2.addItems(featureSet2) Feature_set2list2 = list(featureSet2) # Fill 2end combobox slotLambda = lambda: self.myFunction(layer, Feature_set2list2) self.dlg.comboBox_2.currentIndexChanged.connect(slotLambda)
The if statment does not seem to work,it only gives me the districts of the first state, and does not change after further changes. can somebody point out the problem or show me how it's done?