Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Oct 19, 2017 8:37 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Listbox auto-search
PostPosted: Mon Jun 03, 2013 9:10 am 
Offline

Joined: Sat Feb 09, 2013 7:41 pm
Posts: 5
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.

Cheers,
Carl.


Top
 Profile  
Reply with quote  
 Post subject: Re: Listbox auto-search
PostPosted: Mon Jun 03, 2013 9:52 am 
Offline

Joined: Thu Apr 10, 2008 6:03 am
Posts: 303
Location: Paris-La Défense, France
Hi,

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
wline=0
end if

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

Return True
end if
NEXT

_________________
Check my Website for high quality custom controls and classes (no plugins) for Windows, Mac OS and Linux
REALBasic 2012 R2 on Win 7 & Mac OS X


Top
 Profile  
Reply with quote  
 Post subject: Re: Listbox auto-search
PostPosted: Mon Jun 03, 2013 11:11 am 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
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.

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group