FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Incremental Search
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM

Incremental Search

Posted: Fri Mar 02, 2012 10:48 PM
To All

I am trying to reproduce an old VB program that uses an incremental search in a Get field and displays the search in a listbox as the user types. I am using an Access recordset database.

On the surface this sounds like a daunting task because I there is only 'when' and 'valid' clause .. Here is a screen shot of the application I am trying to duplicate and second is the app I am in the process of creating.

Any help would be GREATLY appreciated !

Rick Lipkin

Old Program I am trying to duplicate


New Program
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 04:46 PM
Hi Rick;

I think a simple solution would be to make the oGet where the Name is typed the oSeek property of the xbrowse:
Code (fw): Select all Collapse
oBrw:oSeek := oGet


That should work.



Reinaldo.
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 05:55 PM

Reinaldo

In reviewing the xBrowse source .. there is a ::cSeek variable .. are you suggesting something like this ? ::cSeek := oGet ??

If so how would you send that value as the user is typing ?

Thanks
Rick

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 06:04 PM
Actually, I'm speaking of the oSeek property not the cSeek property. I guess it could also be done with the cSeek...?

Here is what I mean; let's say the get for the last name on the form looks like this:


Code (fw): Select all Collapse
   @ 1, 01 GET ::oSeek VAR ::cSearch OF oDlg SIZE 145, 35 UPDATE


Then on the xbrowse definition you would say:
Code (fw): Select all Collapse
      oBrw:oSeek      := ::oSeek


And you would have to worry about anything else. Of course you would need to have the dbf ordered by a key such that when the seek is executed it would move to the closest match. If xbrowsing an array, then make sure the array is sorted by the column containing the data being searched. I pretty sure that would work. Try it.


Reinaldo.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 09:56 PM
Rick,

You have to use the ON CHANGE clause of the GET and perform a oBrw:Seek() of the written text:

Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

   local oDlg, cName := Space( 100 ), oBrw
   
   DEFINE DIALOG oDlg SIZE 400, 400
   
   @ 1, 5 GET cName SIZE 120, 12 ;
      ON CHANGE ( oBrw:GoDown(), MsgBeep() ) // oBrw:Seek( AllTrim( cName ) )
      
   @ 3, 1 XBROWSE oBrw ARRAY { "One", "Two", "Three", "Four", "Five" } OF oDlg ;
      SIZE 185, 150  
   
   oBrw:CreateFromCode()
   
   ACTIVATE DIALOG oDlg CENTERED

return nil


Replace oBrw:GoDown() with oBrw:Seek( AllTrim( cName ) ) for a DataBase
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 10:07 PM

Rick,

You have also a very good example at FWH\samples\xbincflt.prg though in that case the user types directly on the xbrowse

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM

Re: Incremental Search

Posted: Sat Mar 03, 2012 11:01 PM

Antonio

Thank you for your suggestions .. what I was hoping to achieve here using an Access recordset was something like this:

Select * from Customer
oRs:Filter := "lname = 'bogus'" // gives me a eof recordset so the listbox is empty

Then as the user types I was hoping to modify the filter condition

cLname := "Smi"

oRs:Filter := ""
oRs:Filter := "lname like '"+cLname+"'%"

I will play with the ON CHANGE and maybe create a function that contains my filter updates .. Let me know what you think if I am on the right track.

Many Thanks
Rick Lipkin

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Incremental Search

Posted: Sun Mar 04, 2012 08:45 AM

Rick,

Yes, it seems fine to me :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: Incremental Search

Posted: Sat Oct 06, 2012 09:58 PM
I wanted to include incremental seek on xBrowse, but doesn't work.
The say is empty nothing possible to type. Maybe because of using Resources ?



REDEFINE XBROWSE oBrw ID 110 OF oFld:aDialogs[1] ;
COLUMNS "Number", "Name1", "Name2", "Notes" ;
FIELDS (5)->NUMBER, (5)->NAME1, (5)->NAME2, (5)->NOTES ;
FIELDSIZES 100, 100, 100 ,150 ;
HEADERS "Field 1", "Field 2", "Field 3", "Notes" ;
JUSTIFY .T., nil, .T., .T. // AUTOCOLS AUTOSORT

SetBrwStyle( oBrw )

// 1. Index
oBrw:aCols[1]:cSortOrder := "Number"
oBrw:aCols[1]:oHeaderFont:= oFont2
oBrw:aCols[1]:bClrHeader := {|| { 255,0 } }
oBrw:aCols[1]:AddResource( "B_Select" )
oBrw:aCols[1]:nHeadBmpNo := 1
oBrw:aCols[1]:bLClickHeader = { | nMRow, nMCol, nFlags, Self | ;
oBrw:aCols[1]:bClrHeader := {|| { 255,0 } }, ;
oBrw:aCols[3]:bClrHeader := {|| { 16711680,0 } }, ;
oBrw:Refresh() }
oBrw:aCols[1]:nHeadBmpAlign := AL_LEFT

oBrw:aCols[2]:oHeaderFont:= oFont2
oBrw:aCols[2]:bClrHeader := {|| { 0, } }

// 2. Index
oBrw:aCols[3]:cSortOrder := "NAME2"
oBrw:aCols[3]:oHeaderFont:= oFont2
oBrw:aCols[3]:bClrHeader := {|| { 16711680,0 } }
oBrw:aCols[3]:AddResource( "B_Select" )
oBrw:aCols[3]:nHeadBmpNo := 1
oBrw:aCols[3]:bLClickHeader = { | nMRow, nMCol, nFlags, Self | ;
oBrw:aCols[3]:bClrHeader := {|| { 255,0 } }, ;
oBrw:aCols[1]:bClrHeader := {|| { 16711680,0 } }, ;
oBrw:Refresh() }
oBrw:aCols[3]:nHeadBmpAlign := AL_LEFT

oBrw:aCols[4]:nEditType := EDIT_BUTTON
oBrw:aCols[4]:bEditBlock := { | r, c, o | EditNotes( r, c, o, EditData[10] ) }

oBrw:bLClicked := { | nRow, nCol | LOAD_FIEDS() }
oBrw:bChange := { || LOAD_FIEDS() }

oBrw:lIncrFilter := .t.
oBrw:lSeekWild := .t.

REDEFINE SAY oBrw:oSeek PROMPT oBrw:cSeek ID 120 PIXEL ;
OF oFld:aDialogs[1] COLOR CLR_BLACK,CLR_YELLOW PICTURE '@!'


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.

Continue the discussion