[Gambas-user] Select an entry in a combo or list box by keypress - Is there a better way.

Ian Roper ian.roper at ...1974...
Sat Sep 13 07:37:22 CEST 2008


Greetings all,

I am looking for a better way to locate and select an entry in a combo
or list box by pressing a series of keys.

I have been able to do this with the following code but there must be a
better way. ?

It would be nice to have this as a standard method for these sort of
controls. :)

'Pressing Esc clears the search string.
'Label_Search displays the current search string.

PUBLIC SUB Listbox_KeyPress()
   DIM Count AS Integer
   DIM Found AS Boolean
   DIM SearchLen AS Integer
   
   Found = FALSE
   
   IF Key.Code = Key.Esc THEN 
      SearchString = "" 
      SearchLen = 0 
      Label_Search.Text = "No Search" 
   ELSE
      SearchString = SearchString & UCase(Key.Text)
      SearchLen = Len(SearchString)
      Label_Search.text = SearchString
   ENDIF 
   
   REPEAT 
      IF UCase(Left(Listbox[Count].Text, SearchLen)) = (SearchString)
THEN
         Found = TRUE
      END IF   
      INC Count
   UNTIL Found OR (Count = (Listbox.Count - 1)) 
  
   IF found THEN Listbox.index = Count - 1
  
END

PUBLIC SUB Listbox_LostFocus()

  SearchString = ""

END


Thank you,

Ian Roper
Western Australia





More information about the User mailing list