DB Drop Down List allows selection that is not in List

Hello, I am using a Drop Down List to select from a DB file. I would like to prevent a selection that is not in the list to be displayed.

Example, if My part number is BB777888 and I enter BB77, and select it, I would like to display EMPTY so we can then choose a correct part number or leave it as EMPTY if we are not using it.

You’ll need to monitor for changes in the selectedLabel property. There are two possibilities for resetting the dropdown.

  • Typing in an invalid entry from a no selection state
  • Typing in an invalid entry from a previous valid entry.

Try this in the propertyChange event:

if event.propertyName == 'selectedLabel':

	# check for invalid entry from no selection state
	if event.source.selectedValue == event.source.noSelectionValue and event.source.selectedLabel != event.source.noSelectionLabel:
		event.source.selectedLabel = event.source.noSelectionLabel
	
	# check for invalid entry from previous valid entry
	if event.source.selectedValue != event.source.noSelectionValue and event.source.selectedLabel != event.source.selectedStringValue:
		event.source.selectedValue = -1

OK. So I will need to try that code in my “Accept” button on the propertyChange tab, correct?

I had put mine in the propertyChange event of the dropdown.

OK. Thank you for the help. I will give it a shot tonight.

Thank you again for the help. I added your code to the Drop Down and it got me what I asked for. After that I found another bug but was able to fix because of how you helped me.

I compared my Material Choice text to the Drop down selected string value to enable my Accept button.

Works like a champ…

Nothing better than a day where you learn at least 10 new things…

1 Like