== Introduction == This recipe offers a {{{wxListBox}}} subclass that will jump directly to the item that starts with the phrase you type in (as opposed to selecting the next item that starts with the character you just typed). It is similar to the functionality provided by Mozilla's select boxes, while the default behavior is similiar to Internet Explorer's. == What Objects are Involved == Only {{{wxListBox}}} itself. == Process Overview == When the user presses any key except backspace, that key is appended to a phrase (backspace erases the last character). The {{{wxListBox}}} then deselects any items already selected and goes to the first item that begins with the phrase typed. The process is case insensitive. == Special Concerns == If you plan to use any method other than Set to add items to the {{{wxListBox}}} (such as Append), you need to provide a method for it that sets self.choices to the items that make up the {{{wxListBox}}}. == Code Sample == {{{ #!python import wx class PromptingListBox(wx.ListBox): def __init__(self, parent, id, choices = [], style = 0): self.choices = choices self.phrase = '' wx.ListBox.__init__(self, parent, id, choices = choices, style = style) self.Bind(wx.EVT_CHAR, self.EvtChar, self) return 0 def EvtChar(self, event): keycode = event.GetKeyCode() if keycode == 8: # Backspace removes last letter self.phrase = self.phrase[:-1] elif keycode == 127: # Delete erases phrase self.phrase = '' elif keycode not in range(256): # Do the default action for nonascii keycodes event.Skip() return 0 else: self.phrase += chr(keycode).lower() for item in self.GetSelections(): self.Deselect(item) if self.phrase == '': # Don't select 1st item if phrase is blank return 0 for choice in self.choices: choice = choice.lower() if choice.startswith(self.phrase): self.SetStringSelection(choice) return 0 return 0 def Set(self, choices): self.choices = choices self.phrase = '' wx.ListBox.Set(self, choices) return 0 }}} === Comments === Send questions or comments to [[mailto:jkevans@pacbell.net|Jeremy Evans]]. [[Bill Bell]]'s [[Combo Box that Suggests Options]] gave me the general idea about how to do this, this code is based on it.