Real Software Forums

Listbox auto-search
Page 1 of 1

Author:  Carl4 [ Mon Jun 03, 2013 9:10 am ]
Post subject:  Listbox auto-search

I am converting some of my older legacy VB6 code to RB and having a lot of fun and learning in the process - I love RB! I can't help but compare though, and with VB6, simply highlighting an entry in a listbox, then typing a character or series of characters would automatically scroll the listbox to the alphabetical area matching what was typed (assuming a sorted listbox). A huge time-saver. It would be great to do the same with RB listboxes. I'm sure this has probably been covered elsewhere in this forum, but I don't really know what terminology would be used.
Is it possible to implement this feature in RealBASIC?
Would be very grateful for a response, or a redirection to an area which might have an answer.


Author:  JeremK [ Mon Jun 03, 2013 9:52 am ]
Post subject:  Re: Listbox auto-search


The Listbox in Realstudio is a very efficient control.

I would start with the "KeyDown" event. In this event, you get the "Key" that was pressed on the Keyboard.

From there, search all lines from the current listindex:

//Search the first row starting with "key"

dim wline as integer =me.listindex
Dim ColFind As Integer = 0 //Search on the first column
if wline=me.ListCount then
end if

FOR i as integer = wline+1 to me.ListCount -1
if left( me.cell(i, ColFind), 1)=key then

Return True
end if

Author:  ktekinay [ Mon Jun 03, 2013 11:11 am ]
Post subject:  Re: Listbox auto-search

You can expand on that by writing code that will let it handle cases where a user types a phrase instead of a letter. So if I type, "hin" within a certain amount of time, it will skip the row that contains "hand that rocks the cradle" and jump to "hindenberg" instead. You might want to create some kind of indexing system too.

You should do this as a subclass of the ListBox so you can reuse it.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group