FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Combo box incremental search
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Combo box incremental search
Posted: Tue Jul 03, 2012 09:06 PM

The class for the combobox ( dropdown ) shows a lIncSearch data item which would appear to implement a method that permits incremental searching of a list ( array ).

However: oCombo:lIncSearch := .t.

Does not activate such an activity.

What am I missing here ? I have clients who have a very long list in the box and want to move the highlight bar based on what they are typing !

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Combo box incremental search
Posted: Wed Jul 04, 2012 06:10 AM
Hello Tim,
I would suggest you to use comboM (TComboMetro).
The new combo class (source\combom.prg) uses internally a xBrowse with all the xBrowse power.

Best regards,
Otto



Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Combo box incremental search
Posted: Wed Jul 04, 2012 07:30 AM
Hi Tim,

here is an implementation of an incremental search in a combobox. I did not test it, but maybe it helps.

Code (fw): Select all Collapse
/*
Purpose  : Provides incremental search to a regular combobox.
Notes    : After defining your ComboBox run SetIncr(oCbx).
         : Include the attached prg in your project.
Author   : Byron Hopp, (Matrix Computer Services) <mcs3@ix.netcom.com>
Date     : 7/1/00

Notes: There is no handling of backspaces. You can use the up and down arrow 
keys also (while the dropdown is not down). Using a space resets the seach.

Modified to make case insensitive and to handle DBCombo's also, by James 
Bott, 5/21/04. Tested under FWH 2.4/Harbour 43.
*/

FUNCTION SetIncr(oCbx)
    oCbx:bKeyChar   := {|nKey,nFlags| FindIncr(oCbx,nKey)}
    oCbx:bGotFocus  := {|| oCbx:Cargo := "",oCbx:SetFocus()}
RETURN NIL

FUNCTION FindIncr(oCbx,nKey)
    LOCAL  nNewEle  := 0
    IF nKey <> 32
        oCbx:Cargo += upper( CHR(nKey) )
        if oCbx:classname =="TCOMBOBOX"
           oCbx:Set(IIF( (nNewEle := ASCAN(oCbx:aItems, {|x| upper(x) = 
oCbx:Cargo} )) > 0,nNewEle,oCbx:nAT))
        else // for TDBCombo
           oCbx:Set(IIF( (nNewEle := ASCAN(oCbx:aList, {|x| upper(x) = 
oCbx:Cargo} )) > 0,nNewEle,oCbx:nAT))
        endif
     ELSE
        oCbx:Cargo := ""
        oCbx:Set(1)
    ENDIF
RETURN oCbx:nAT
kind regards

Stefan
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Thu Jul 05, 2012 05:15 PM

Stefan,

I tried it ... once the Get got focus, it just constantly ran, flashing, with no escape.

Otto,

This is not a metro app ...

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Combo box incremental search
Posted: Thu Jul 05, 2012 06:14 PM

Tim,
you can use ComboM with a Standard WINDOWS application.
I think the use of xBrowse insite the comboBox offers great possibilities.
Best regards,
Otto

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 12:05 AM

Otto,

My program uses resources for all the dialogs and controls.

I did look at the control you suggested, but it does not appear to allow a REDEFINE of an RC control ...
Perhaps I am missing something essential and you can point me to a sample.

Thanks.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 07:17 AM

Hello Tim,
yes you are right. I didn't thought on that.
I don't think that this option will be built in as the use of resources is not useful for Metro inspired programs.
Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 10:02 AM
Tim,

This example works fine but requires that the user types the whole item chars:

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

function Main()

   local oDlg, oCbx, cSearch := Space( 100 ), aItems := { "africa", "america", "asia", "europe", "oceania" }

   DEFINE DIALOG oDlg SIZE 400, 300

   @ 2.4, 1.2 COMBOBOX oCbx VAR cSearch ITEMS aItems OF oDlg SIZE 180, 150

   oCbx:lIncSearch = .T.

   ACTIVATE DIALOG oDlg CENTERED

return nil


With this litte change in FWH Class TComboBox is no longer needed that you write all its chars :-)
line 557 combobox.prg
Code (fw): Select all Collapse
            if ::lCaseSensitive
               nNewAt = AScan( ::aItems, { | x | SubStr( x, 1, Len( ::cSearchKey ) ) == ::cSearchKey } )
            else
               nNewAt = AScan( ::aItems, { | x | SubStr( Upper( x ), 1, Len( ::cSearchKey ) ) == ::cSearchKey } )
            endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 08:30 PM

.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 08:33 PM

I made the changes and linked in combobox.prg

I'm calling the combobox this way:

REDEFINE COMBOBOX oCmboBx VAR oInvr:invman ITEMS aMan ID 767 OF oDiw STYLE CBS_DROPDOWN ;
MESSAGE "Enter the manufacturer of this product" UPDATE
oCmboBx:lIncSearch := .t.

And the control is:

CONTROL "", 767, "ComboBox", WS_BORDER|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP, 248, 55, 92, 162

However, it does not function properly ....

Actually Its not refreshing the value in the get when I type, but if I click on the down arrow, the proper element is highlighted.

Tim

What is wrong with the above ?

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 08:38 PM

The problem is that you are uisng the CBS_DROPDOWN style and it is not assumed to be used.

We could implement it for that case too. But then you will have to control with the VALID that the typed item is one of the existing items.

If you don't use the CBS_DROPDOWN style, then the user can only type valid items contents.

I am not sure if I am properly explaining it :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Fri Jul 06, 2012 08:57 PM

So what style / control should I use ( I assume both in the REDEFINE and the .rc ) ?

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Combo box incremental search
Posted: Sat Jul 07, 2012 12:24 PM

In the resources you use: CBS_DROPDOWNLIST and in the PRG you don't need any.

Please run FWH\samples\combos.prg. The one on the right is the right one :-)

You can review combos.rc to see how it is declared, thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Combo box incremental search
Posted: Sat Jul 07, 2012 09:31 PM

The problem is that we need to be able to add an entry not on the list ...

People like to just type in values sometimes ( or always ).

That, by definition, is the combobox vs the drop down list.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion