Prevent ArcMap Python Add-in Combobox from resetting text cursor on refresh()

837
1
06-02-2017 04:59 PM
JerryCorum1
New Contributor III

Hello everyone,

I am trying to replace an old VB Dockable Window add-in we've had around for a while before we upgrade to ArcGIS Desktop 10.5 and I am having some trouble.  I've been working on it for a few days but have finally hit a brick wall (with my head... repeatedly).

The tool basically has a dropdown menu of several layers that don't have to be in the map document and allows the user to search for, say, an address or quarter section grid number, and then zooms the user to that location.  It's been around since long before my time here, and when I suggested using the built-in Find tool people didn't want to always have the layers in the map so it got shot down.

I've accomplished replacing the adding with a Python Add-in partly, but I am running into some trouble - the old VB add-in was able to show options like a lookahead or autocomplete feature - i.e. type in 123 and it would pop the dropdown of the combobox down with a sorted list of the 10 most likely items you are looking to zoom to that start with 123.  

I have a search cursor that can get me the item array for that lookahead ability, however I cannot find how to get the combobox to dropdown with the code and when I set the combobox.items equal to the array and call the refresh() method to show the new items, it moves the typing cursor in the search combobox back to the beginning of the string.  

I have two questions I guess.  

1) Can I automatically pop open the combobox's dropdown list when someone starts typing?

2) Does anybody know a way to either prevent the typing cursor from moving to the beginning of the combobox string within the refresh() or onEditChange methods or to maybe get the length of the string typed into the combo box and in the code, manually put the typing cursor there?

Right now I'm doing this in the combobox onEditChange method:

self.items = sorted(lookAheadItems[:10])
self.refresh()

lookAheadItems is just an array populated with a search cursor any time there are more than 3 characters typed into the combobox.  Every time it's triggered the cursor (not the search cursor, the insert text cursor) moves back to the beginning of the string.  Can I prevent that somehow?  

Thank you!

1 Reply