试试终止系统对按键的默认解释:
DO CASE
CASE k=24
Thisform.list1.SetFocus
Nodefault
ENDCASE ------解决思路---------------------- 将下面代码复制到一个prg中运行,然后可以直接从ComboBox中下拉选择内容,也可在ComboBox上输入要查询的关键字,边输边筛选,然后可以鼠标或上下键选择筛选出来内容。
Add Object combo1 As ComboBox With ;
Height = 24, ;
Left = 48, ;
Style = 0, ;
Top = 24, ;
Width = 144, ;
Name = "Combo1"
Add Object list1 As ListBox With ;
Height = 97, ;
Left = 192, ;
Top = 84, ;
Visible = .F., ;
Width = 108, ;
Name = "List1"
Procedure Init
Create Cursor t1 (fl1 C(20))
For lnI=0 To 23
Insert Into t1 Values (Chr(65+lnI)+Chr(97+lnI)+'-'+Chr(66+lnI)+Chr(98+lnI)+'-'+Chr(67+lnI)+Chr(99+lnI)+Transform(lnI))
Endfor
Locate
Scan
Thisform.Combo1.AddItem(fl1)
Endscan
Endproc
Procedure KeyPress
Lparameters nKeyCode, nShiftAltCtrl
If (nKeyCode=5 Or nKeyCode=24 Or nKeyCode=13) And This.List1.Visible And This.List1.ListItemId>0 And This.Combo1.Tag='1'
If nKeyCode=13
This.Combo1.DisplayValue=Thisform.List1.ListItem(Thisform.List1.ListItemId,1) && 此种方式不会触发Text1的InteractiveChange事件
This.List1.Visible=.F.
Else
lnListID=Iif(nKeyCode=5,Max(This.List1.ListItemId-1,1),Min(This.List1.ListItemId+1,This.List1.ListCount))
This.List1.ListItemId=lnListID
This.Combo1.DisplayValue=Thisform.List1.ListItem(Thisform.List1.ListItemId,1)
Nodefault
Endif
Endif
Endproc
Procedure combo1.LostFocus
This.Tag=''
Endproc
Procedure combo1.KeyPress
Lparameters nKeyCode, nShiftAltCtrl
If Between(nKeyCode,48,57) ; && 0-9
Or Between(nKeyCode,97,122) ; && a-z
Or Between(nKeyCode,65,90) ; && A-Z
Or nKeyCode=7 ; && DEL
Or nKeyCode=127 ; && BACKSPACE
Or (nKeyCode>127 And nKeyCode<>160) && 汉字
Thisform.List1.Tag='1' && 自动筛选
Else
Thisform.List1.Tag='' && 不筛选
Endif
Endproc
Procedure combo1.InteractiveChange
If Thisform.List1.Tag='1'
Thisform.List1.Tag=''
lcCombo1Val=Upper(Alltrim(This.DisplayValue))
If !Empty(lcCombo1Val)
Thisform.List1.RowSource=Null
Select fl1 Into Cursor ct2 From t1 Where (Upper(fl1) Like "%&lcCombo1Val.%")
Thisform.List1.RowSourceType=6
Thisform.List1.RowSource="ct2.fl1"
If Reccount('ct2')>0
Thisform.List1.ListItemId=1
Thisform.List1.Visible=.T.
Else
Thisform.List1.Visible=.F.
Endif
Else
Thisform.List1.Visible=.F.
Endif
Endif
Endproc