A better Drop Picker
Posted: Sun Apr 26, 2015 2:36 pm
Here is a sample program that drops down a browse below a get when a value is typed in the get and there are 1 or more matches in the browse.
Functionality is similar to Windows drop downs when selecting a file from the file dialog.
Functionality is similar to Windows drop downs when selecting a file from the file dialog.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"
FUNCTION Main()
LOCAL GetList[0], GetOptions, cName, aNames, cPerformer, oBrowse
cPerformer := Space(30)
aNames := PerformerNames()
@ 0,0 DCSAY 'Enter Performer Name' GET cPerformer ;
SAYSIZE 0 SAYBOTTOM ;
KEYBLOCK {|a,b,o|DropDownNames(a,o,@cPerformer,aNames,oBrowse), ;
DC_BrowseAutoSeek(a,o,oBrowse,aNames)}
@ 1,16 DCBROWSE oBrowse DATA aNames SIZE 35,10 ;
FONT '10.Lucida Console' ;
FILTER {|a|a[2]} ;
LOSTFOCUS {|a,b,o|o:hide()}
DCBROWSECOL ELEMENT 1 WIDTH 30 PARENT oBrowse
DCREAD GUI FIT TITLE 'Scoped Drop-Down' EVAL {||oBrowse:hide()}
RETURN nil
* -----------
PROC appsys ; RETURN
* -----------
STATIC FUNCTION DropDownNames( nKey, oGet, cPerformer, aNames, oBrowse )
LOCAL i, nFound, cName, nLen, aPerformers, nCount := 0
IF nKey == xbeK_ENTER
cPerformer := Pad(aNames[oBrowse:arrayElement,1],30)
oGet:setData(cPerFormer)
ELSEIF (Chr(nKey) < 'A' .OR. Chr(nKey) > 'z') .AND. !nKey $ {xbeK_SPACE,xbeK_BS}
RETURN nil
ENDIF
oGet:getData()
cName := Alltrim(Upper(cPerformer))
nLen := Len(cName)
nFound := AScan( aNames, {|a|Left(Upper(a[1]),nLen) == cName} )
FOR i := 1 TO Len(aNames)
aNames[i,2] := .f.
NEXT
IF nFound > 0 .AND. !Empty(cName)
FOR i := 1 TO Len(aNames)
IF Left(Upper(aNames[i,1]),nLen) == cName
aNames[i,2] := .t.
ENDIF
NEXT
oBrowse:goTop()
oBrowse:forceStable()
oBrowse:refreshAll()
oBrowse:show()
SetAppFocus(oGet)
DC_ClearEvents()
ELSE
oBrowse:hide()
oBrowse:goTop()
oBrowse:forceStable()
oBrowse:refreshAll()
ENDIF
RETURN nil
* ------------
STATIC FUNCTION PerformerNames()
LOCAL aNames1[0], aNames2, i
aNames2 := { ;
'Annie Hall', ;
'Arlo Guthrie', ;
'Bette Midler', ;
'Bob Dylan', ;
'Bobbie Gentry', ;
'Buddy Holly', ;
'Canned Heat', ;
'Carol Elliot', ;
'Carole King', ;
'Caroline Aikin', ;
'Cat Stevens', ;
'Catie Curtis', ;
'Cheryl Wheeler', ;
'Chuck Prophet', ;
'Chuck Pyle', ;
'Crosby, Stills, Nash', ;
'Danny Kaye', ;
'Dar Williams', ;
'Dr Hook', ;
'Eliza Gilkyson', ;
'Elton John', ;
'Elvis Presley', ;
'Gail Davies', ;
'Glenn Miller', ;
'Gordon Rowland', ;
'Greg Brown', ;
'Harry McClintock', ;
'Itzhak Perlman', ;
'James Taylor', ;
'Jan Stanfield', ;
'Jefferson Airplane', ;
'Jim Croce', ;
'Jimi Hendrix', ;
'Jimmy Dean', ;
'John Denver', ;
'Joni Mitchell', ;
'Journey', ;
'Kevin Welch', ;
'Krystian Zimermann', ;
'Led Zeppelin', ;
'Lyle Lovett', ;
'Lynn Miles', ;
'Madeleine Peyroux', ;
'Michael Jackson', ;
'Michael Lille', ;
'Mumbo Gumbo', ;
'Norah Jones', ;
'Ray Charles', ;
'Richard Pryor', ;
'Richard Shindell', ;
'Richie Havens', ;
'Robin Williams', ;
'Roy Orbison', ;
'Sam Cooke', ;
'Slobberbone', ;
'Steppenwolf', ;
'Susan Werner', ;
'Ten Years After', ;
'The Beatles', ;
'The Doors', ;
'The Eagles', ;
'The Flatlanders', ;
'The Moody Blues', ;
'Tim Bays', ;
'Toby Keith', ;
'Tom Paxton', ;
'Tom Petty', ;
'Tom Prasada-Rao', ;
'Van Morrison', ;
'Vance Gilbert', ;
'Vic Chestnutt', ;
'Willie Nelson', ;
'Yo-yo Ma', ;
'Yundi Li'}
FOR i := 1 TO Len(aNames2)
AAdd(aNames1,{ aNames2[i], .t. } )
NEXT
RETURN aNames1