怎樣實現Combo1下拉

golden8510 2009-09-30 10:06:23
怎樣實現Combo1下拉;
我用Combo1來選擇用戶工號;
輸入的時候怎么不出現下拉呢;
例:M233,M444,M449,M514
正常應該輸入M的時候出現,M233,M444,M449,M514
再輸入4的時候,出現,M444,M449
...全文
421 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
golden8510 2009-11-01
  • 打赏
  • 举报
回复
UP!
golden8510 2009-10-16
  • 打赏
  • 举报
回复
Up!
golden8510 2009-10-09
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 of123 的回复:]
'组合框列表增量查找,注意,不支持中文

Public Sub ComboIncrementalSearch(cbo As _
ComboBox, KeyAscii As Integer)
Static dTimerLast As Double
Static sSearch As String
Static hWndLast As Long
Dim nRet As Long
Const MAX_KEYPRESS_TIME = 0.5
' Weed out characters that are not scanned
If (KeyAscii < 32 Or KeyAscii > 127) _
Then Exit Sub
If (Timer - dTimerLast) < _
MAX_KEYPRESS_TIME And hWndLast = _
cbo.hWnd Then
sSearch = sSearch & Chr$(KeyAscii)
Else
sSearch = Chr$(KeyAscii)
hWndLast = cbo.hWnd
End If
' Search the combo box
nRet = SendMessage(cbo.hWnd, _
CB_FINDSTRING, -1, ByVal sSearch)
If nRet >= 0 Then
cbo.ListIndex = nRet
End If
KeyAscii = 0
dTimerLast = Timer
End Sub
[/Quote]
無法運行,
出現Bug;
of123 2009-10-09
  • 打赏
  • 举报
回复
上面的需要函数和常量声明

Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long

Private Const CB_FINDSTRING = &H14C '在 ComboBox 中模糊查找
of123 2009-10-09
  • 打赏
  • 举报
回复
'组合框列表增量查找,注意,不支持中文

Public Sub ComboIncrementalSearch(cbo As _
ComboBox, KeyAscii As Integer)
Static dTimerLast As Double
Static sSearch As String
Static hWndLast As Long
Dim nRet As Long
Const MAX_KEYPRESS_TIME = 0.5
' Weed out characters that are not scanned
If (KeyAscii < 32 Or KeyAscii > 127) _
Then Exit Sub
If (Timer - dTimerLast) < _
MAX_KEYPRESS_TIME And hWndLast = _
cbo.hWnd Then
sSearch = sSearch & Chr$(KeyAscii)
Else
sSearch = Chr$(KeyAscii)
hWndLast = cbo.hWnd
End If
' Search the combo box
nRet = SendMessage(cbo.hWnd, _
CB_FINDSTRING, -1, ByVal sSearch)
If nRet >= 0 Then
cbo.ListIndex = nRet
End If
KeyAscii = 0
dTimerLast = Timer
End Sub
golden8510 2009-10-08
  • 打赏
  • 举报
回复
Help!
golden8510 2009-10-07
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 forevermini 的回复:]
Option Explicit
Const CB_FINDSTRING = &H14C
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer

iStart = 1
iStart = Combo1.SelStart
If iLeftOff <> 0 Then
Combo1.SelStart = iLeftOff
iStart = iLeftOff
End If
sString = CStr(Left(Combo1.Text, iStart))
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal CStr(Left(Combo1.Text, iStart)))

If Combo1.ListIndex = -1 Then
iLeftOff = Len(sString)
Combo1.Text = sString
End If
Combo1.SelStart = iStart
iLeftOff = 0
End Sub

[/Quote]
結果好像還有點Bug;
輸入2時,
只出現23,
不出現25;
rmini 2009-10-07
  • 打赏
  • 举报
回复
Option Explicit
Const CB_FINDSTRING = &H14C
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer

iStart = 1
iStart = Combo1.SelStart
If iLeftOff <> 0 Then
Combo1.SelStart = iLeftOff
iStart = iLeftOff
End If
sString = CStr(Left(Combo1.Text, iStart))
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal CStr(Left(Combo1.Text, iStart)))

If Combo1.ListIndex = -1 Then
iLeftOff = Len(sString)
Combo1.Text = sString
End If
Combo1.SelStart = iStart
iLeftOff = 0
End Sub
golden8510 2009-10-04
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 veron_04 的回复:]
引用 9 楼 golden8510 的回复:
引用 8 楼 veron_04 的回复:
引用 5 楼 golden8510 的回复:
引用 3 楼 veron_04 的回复:
你需要使用模糊匹配来实现下拉功能。比如你输入一个“M2”那么就会在下拉列表中出现“M233”

怎樣模糊查詢;


1、你的下拉列表中的项目都得存在数据库中
2、使用Sql模糊查询语句查询数据库,比如你查询:M  数据库中有:M2、M3、M4三个项目,那么将这三个项目添加到下拉列表中即可。这样可以实现动态内容显示。

Code As Follow:
sql = "select *from NameInfo where name like '%'"
無法實現下拉;


应该是:sql = "select *from NameInfo where name like 'M%'"

[/Quote]
[size=10px]如果我的首字母不相同呢?
[color=#0000FF]应该是:sql = "select *from NameInfo where name like 'M%'"[/[/color]size]
是否有Bug;
贝隆 2009-10-04
  • 打赏
  • 举报
回复
Option Explicit
Const CB_FINDSTRING = &H14C
'Combo的自动查询技术
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long



Private Sub Combo1_Change()

Dim iStart As Integer

Dim sString As String

Static iLeftOff As Integer


iStart = 1

iStart = Combo1.SelStart


If iLeftOff <> 0 Then

Combo1.SelStart = iLeftOff

iStart = iLeftOff

End If


sString = CStr(Left(Combo1.Text, iStart))

Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal CStr(Left(Combo1.Text, iStart)))


If Combo1.ListIndex = -1 Then

iLeftOff = Len(sString)

Combo1.Text = sString

End If


Combo1.SelStart = iStart

iLeftOff = 0

End Sub

'静态变量 iLeftOff 指定了字符长度。

Private Sub Form_Load()
Combo1.AddItem "12"
Combo1.AddItem "13"
Combo1.AddItem "14"
Combo1.AddItem "123"
Combo1.AddItem "23"
Combo1.AddItem "25"
Combo1.AddItem "35"
End Sub
贝隆 2009-10-04
  • 打赏
  • 举报
回复
你点击向下方向键,就会是25了
golden8510 2009-10-04
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 veron_04 的回复:]
VB codeOptionExplicitConst CB_FINDSTRING=&H14C'Combo的自动查询技术Private DeclareFunction SendMessage Lib"user32" Alias"SendMessageA" (ByVal hwndAsLong, _
ByVal wMsgAsLong, ByVal wParamAsLong, lParamAs A¡­
[/Quote]
結果好像還有點Bug;
輸入2時,
只出現23,
不出現25;
golden8510 2009-10-03
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hpygzhx520 的回复:]
呵呵,这个功能叫自动完成。看绿豆的帖子
[/Quote]
能把引用附上嗎?
hpygzhx520 2009-10-03
  • 打赏
  • 举报
回复
呵呵,这个功能叫自动完成。看绿豆的帖子
golden8510 2009-10-03
  • 打赏
  • 举报
回复
Up!
贝隆 2009-10-03
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 golden8510 的回复:]
引用 8 楼 veron_04 的回复:
引用 5 楼 golden8510 的回复:
引用 3 楼 veron_04 的回复:
你需要使用模糊匹配来实现下拉功能。比如你输入一个“M2”那么就会在下拉列表中出现“M233”

怎樣模糊查詢;


1、你的下拉列表中的项目都得存在数据库中
2、使用Sql模糊查询语句查询数据库,比如你查询:M  数据库中有:M2、M3、M4三个项目,那么将这三个项目添加到下拉列表中即可。这样可以实现动态内容显示。

Code As Follow:
sql = "select *from NameInfo where name like '%'"
無法實現下拉;
[/Quote]

应该是:sql = "select *from NameInfo where name like 'M%'"
getemail 2009-10-03
  • 打赏
  • 举报
回复
Private Const WM_SETREDRAW = &HB
Private Const KEY_A = 65
Private Const KEY_Z = 90
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Long) As Long


Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim sComboText As String
Dim iLoop As Integer
Dim sTempString As String
Dim lReturn As Long
If KeyCode >= KEY_A And KeyCode <= KEY_Z Then
'only look at letters A-Z
sTempString = Combo1.Text
If Len(sTempString) = 1 Then sComboText = sTempString
lReturn = SendMessage(Combo1.hwnd, WM_SETREDRAW, False, 0&)
For iLoop = 0 To (Combo1.ListCount - 1)
If UCase((sTempString & Mid$(Combo1.List(iLoop), _
Len(sTempString) + 1))) = UCase(Combo1.List(iLoop)) Then
Combo1.ListIndex = iLoop
Combo1.Text = Combo1.List(iLoop)
Combo1.SelStart = Len(sTempString)
Combo1.SelLength = Len(Combo1.Text) - (Len(sTempString))
sComboText = sComboText & Mid$(sTempString, Len(sComboText) + 1)
Exit For
Else
If InStr(UCase(sTempString), UCase(sComboText)) Then
sComboText = sComboText & Mid$(sTempString, Len(sComboText) _
+ 1)
Combo1.Text = sComboText
Combo1.SelStart = Len(Combo1.Text)
Else
sComboText = sTempString
End If
End If
Next iLoop
lReturn = SendMessage(Combo1.hwnd, _
WM_SETREDRAW, True, 0&)
End If
End Sub

Sub Form_load()
Combo1.AddItem "Alpha"
Combo1.AddItem "Beta"
Combo1.AddItem "Charlie"
Combo1.AddItem "Delta"
Combo1.AddItem "Dingo"
End Sub



golden8510 2009-10-03
  • 打赏
  • 举报
回复
Up!
golden8510 2009-10-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 veron_04 的回复:]
你需要使用模糊匹配来实现下拉功能。比如你输入一个“M2”那么就会在下拉列表中出现“M233”
[/Quote]
怎樣模糊查詢;
golden8510 2009-10-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 imustworking 的回复:]
你必须让Combox控件,获得焦点后,自动下拉。
建议使用forms2.dll中Combox控件,可以简单的设置下拉。VB设计中预定的Combox,需要用API函数让其下拉。
[/Quote]
forms2.dll中Combox控件與VB標準Combox控制有什么區別嗎?
加载更多回复(7)

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧