求助:如何利用combobox控件实现联想输入?
求助:如何利用combobox控件实现联想输入?以下建立了三个控件,combo1,combo2,text1
其中,combo1为vb默认的combox控件
combo2为form2.0中的combobox控件
formload时,赋值一个数组
目的:当从combo1或combo2中输入数组二列最后几位时,能在复选框出现符合条件的记录,
选择某个复选框时,能把数组一列值显示在text1中.
如输入1,复选框additem "14001122331", "2500177331", "14001166331";选弟一条,text显示a
如输入1420,复选框additem "3400121420";选弟一条,text显示d
以下代码都不能实现效果,请教高手赐教!!
Option Base 1
Dim myarray()
'========================================================
Private Sub Form_Load()
ReDim myarray(4, 2)
myarray(1, 1) = "a": myarray(1, 2) = "14001122331"
myarray(2, 1) = "b": myarray(2, 2) = "2500177331"
myarray(3, 1) = "c": myarray(3, 2) = "14001166331"
myarray(4, 1) = "d": myarray(4, 2) = "3400121420"
End Sub
'========================以下为vb默认的combox控件====================
Private Sub Combo1_Change()
Dim txta, txtb As String
If Combo1.Text = "" Then
Exit Sub
End If
txta = Trim(Combo1.Text)
txtb = "*" & txta
'-------------把原有复选项清空,
On Error GoTo aabb:
If Combo1.ListCount > 0 Then
For jj = Combo1.ListCount - 1 To 0 Step -1
Combo1.RemoveItem (jj)
Next
End If
aabb:
'-------------记录循环,如果尾数等于combo1.txt值,就写入combo2复选框中------------
For I = 1 To UBound(myarray)
' If Right(rs1(2), Len(txta)) = txta And rs1(2) <> txta Then '如果只是尾数等,写入combo1复选框中
If myarray(I, 2) Like txtb And myarray(I, 2) <> txta Then '如果只是尾数相等,将值写入combo1复选框中
Combo1.AddItem myarray(I, 2)
ElseIf myarray(I, 2) = txta Then '如果全等,将值写入combo1复选框中,并将数组一列值写入text1中。
If Combo1.ListCount = 0 Then: Combo1.AddItem myarray(I, 2)
Text1.Text = myarray(I, 1) 'text1.text不能赋值????
Exit Sub
End If
Next
End Sub
'==============================以下为form2.0中的combobox控件======???====================
Private Sub Combo2_Change()
Dim txta, txtb As String
If Combo2.Text = "" Then
Exit Sub
End If
txta = Trim(Combo2.Text) '========输入14时,Combo2.Text值会变成14001122331,=====????????
txtb = "*" & txta
'-------------把原有复选项清空,但将保留text,光标在后
On Error GoTo aabb:
If Combo2.ListCount > 0 Then
Combo2.Clear
Combo2.Text = txta
Combo2.SetFocus
SendKeys "{end}"
End If
aabb:
'-------------记录循环,如果尾数等于combo2.txt值,就写入combo2复选框中------------
For I = 1 To UBound(myarray)
' If Right(rs1(2), Len(txta)) = txta And rs1(2) <> txta Then '如果只是尾数等,写入combo2复选框中
If myarray(I, 2) Like txtb And myarray(I, 2) <> txta Then '如果只是尾数相等,将值写入combo2复选框中
Combo2.AddItem myarray(I, 2)
ElseIf myarray(I, 2) = txta Then '如果全等,将值写入combo2复选框中,并将数组一列值写入text1中。
' If Combo2.ListCount = 0 Then: Combo2.AddItem myarray(I, 2) 'combo2会报错???
Text1.Text = myarray(I, 1)
Exit Sub
End If
Next
End Sub
--------------------编程问答-------------------- 参考下这个http://topic.csdn.net/u/20100225/11/7ea64cb5-694f-4930-8ede-d52da84e32e9.html --------------------编程问答--------------------
谢谢,,
想了会,可以用vb默认的那combox,change后加一个click事件,
再循环一次,赋值到text中,
控件高度通过字体设置调整,,
谢谢您推荐的网址!!!
补充:VB , 控件