VB 组合框的添加与修改

2024-11-22 02:42:19
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Text1.Text = Combo1.Text
Command1.Enabled = False '关闭修改按钮,这个你按要求选择关闭不关闭
Command2.Enabled = True
End Sub

Private Sub Command2_Click()
If Text1.Text <> "" Then
Combo1.List(Combo1.ListIndex) = Text1.Text
Text1.Text = "" '修改完成将text1清空
End If
Combo1.ListIndex = Combo1.ListIndex
Command2.Enabled = False
Command1.Enabled = True '打开修改按钮,这个你按要求选择打开不打开
End Sub

Private Sub Command3_Click()
If Text1.Text = "" Then Exit Sub '判断是否为空,为空则不增加到下拉列表中
Combo1.AddItem Text1.Text
'添加成功,并清空text1
Text1.Text = ""
End Sub

Private Sub Form_Load()
'添加数据
Combo1.AddItem "test1"
Combo1.AddItem "test2"
Combo1.AddItem "test3"
Combo1.ListIndex = 0
Command2.Enabled = False '将确定按钮无效

End Sub