VB中怎么在combobox里面加选项 以下拉列表方式出现如果连数据库取表里的值怎么做
展开全部
在Combo1的下拉事件中加入代码,如下:
Private Sub combo1_DropDown()
Me.combo1.Clear
Dim CN As New ADODB.Connection
CN.Open"Provider=microsoft.jet.oledb.4.0;data source=" & App.Path &"\数据库名称.mdb"
DimJ As Integer
DimST As String
Dimrso As ADODB.Recordset
Setrso = New ADODB.Recordset
ST= "select * from 表名"
rso.Open ST, CN, adOpenKeyset, adLockOptimistic
IfNot rso.EOF Then
rso.MoveFirst
End If
ForJ = 1 To rso.RecordCount
Me.combo1.AddItem rso("字段名")
rso.MoveNext
NextJ
rso.Close
Set CN = Nothing
End sub
Private Sub combo1_DropDown()
Me.combo1.Clear
Dim CN As New ADODB.Connection
CN.Open"Provider=microsoft.jet.oledb.4.0;data source=" & App.Path &"\数据库名称.mdb"
DimJ As Integer
DimST As String
Dimrso As ADODB.Recordset
Setrso = New ADODB.Recordset
ST= "select * from 表名"
rso.Open ST, CN, adOpenKeyset, adLockOptimistic
IfNot rso.EOF Then
rso.MoveFirst
End If
ForJ = 1 To rso.RecordCount
Me.combo1.AddItem rso("字段名")
rso.MoveNext
NextJ
rso.Close
Set CN = Nothing
End sub
展开全部
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "A"
Call 算法1
Case "B"
Call 算法2
Case "C"
Call 算法3
End Select
End Sub
Private Sub Command1_Click() '添加选项
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
Select Case Combo1.Text
Case "A"
Call 算法1
Case "B"
Call 算法2
Case "C"
Call 算法3
End Select
End Sub
Private Sub Command1_Click() '添加选项
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-06
展开全部
combo1.additem "123"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询