vb添加自动搜索组合框
想添加组合框,组合框的数据从数据库中查询,这个组合框自动下拉,输入字的首字母就自动查询符合条件的值并显示红色,
--------------------编程问答--------------------
使用Like语句实现数据库的模糊查询
--------------------编程问答--------------------
我没表达清楚,是要一款下拉框,有两列:Id和Name,输入名字就自动搜索其ID号,
--------------------编程问答--------------------
同意一楼,用SQL查询语句
--------------------编程问答--------------------
呵呵。。。你的问题我刚实现,用ctGrid控件可以实现。可以PM我。
--------------------编程问答--------------------
Private Sub PrepareDatabase()
Dim ErrorCondition As Boolean
ErrorCondition = False
Call objConn
Dim rsItems As New ADODB.Recordset
sqlitems = "SELECT SN,Name FROM Material ORDER BY SN ASC"
rsItems.Open sqlitems, conn, 1, 1
' Disable the file open error handler
On Error GoTo 0
Do While Not rsItems.EOF
' Use the AddComboItem method of the grid to add the products to the first combo box
ctGridMain.AddComboItem 1, rsItems.Fields("SN") + Chr(10) + rsItems.Fields("Name")
rsItems.MoveNext
Loop
End Sub
Private Sub ctGridMain_AfterCellWrite(ByVal nIndex As Long, ByVal nColumn As Integer)
' This event occurs after text within a cell has been changed and written back to the grid.
Dim strText As String
If (nColumn = 0) Then ' If the value entered is in the first column
' Store the value entered into the strText variable
strText = ctGridMain.CellText(nIndex, nColumn)
Call objConn
Dim rsMatName As New ADODB.Recordset
sqlMatName = "SELECT Name From Material WHERE SN='" & strText & "'"
rsMatName.Open sqlMatName, conn, 1, 1
If Not rsMatName.EOF Then ctGridMain.CellText(nIndex, 1) = rsMatName.Fields("Name")
Set rsMatName = Nothing
Set conn = Nothing
End If
If (nColumn = 2 Or nColumn = 3) Then ' If the entry is in the third column (Quantity) or the fourth column (Price in the case of a CUST item)
ctGridMain.CellValue(nIndex, 4) = ctGridMain.CellValue(nIndex, 2) * ctGridMain.CellValue(nIndex, 3) ' Calculate the Total and place it in the fifth column
End If
End Sub
Private Sub ctGridMain_FirstDraw()
PrepareDatabase
End Sub
--------------------编程问答--------------------
有高手的话看下这个代码哪里有问题,程序没问题,不过我写代码不严谨,不知道这样的代码对程序有影响吗?
补充:VB , 数据库(包含打印,安装,报表)