VB按钮控制combo 10
有combo1(已有A、B、C三个项目),其中A对应combo2(A1、A2、A3)。如何使单击按钮时,让combo1=“A”,让combo2=“A1”。下拉菜单的内容已...
有combo1(已有A、B、C三个项目),其中A对应combo2(A1、A2、A3)。
如何使单击按钮时,让combo1=“A”,让combo2=“A1”。
下拉菜单的内容已经设定好:
combo1=“A”时,combo2自动加载“A1”、“A2”、“A3”
combo1="B”时,combo2自动加载“B1”、"B2"、"B3"
。。。。。。
当我在combo1选A时,就可以在combo2中选A1/A2/A3,但是现在我想通过单击一个按钮来实现。求代码!!! 展开
如何使单击按钮时,让combo1=“A”,让combo2=“A1”。
下拉菜单的内容已经设定好:
combo1=“A”时,combo2自动加载“A1”、“A2”、“A3”
combo1="B”时,combo2自动加载“B1”、"B2"、"B3"
。。。。。。
当我在combo1选A时,就可以在combo2中选A1/A2/A3,但是现在我想通过单击一个按钮来实现。求代码!!! 展开
4个回答
展开全部
Private Sub Combo1_Click()
If Combo1.Text = "A" Then
Combo2.Clear
Combo2.AddItem "A1"
Combo2.AddItem "A2"
Combo2.AddItem "A3"
End If
If Combo1.Text = "B" Then
Combo2.Clear
Combo2.AddItem "B1"
Combo2.AddItem "B2"
Combo2.AddItem "B3"
End If
If Combo1.Text = "C" Then
Combo2.Clear
Combo2.AddItem "C1"
Combo2.AddItem "C2"
Combo2.AddItem "C3"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
不用另外设置按钮,选择完combo1后,combo2的内容就直接变了。如果另外添加按钮,太罗嗦了
If Combo1.Text = "A" Then
Combo2.Clear
Combo2.AddItem "A1"
Combo2.AddItem "A2"
Combo2.AddItem "A3"
End If
If Combo1.Text = "B" Then
Combo2.Clear
Combo2.AddItem "B1"
Combo2.AddItem "B2"
Combo2.AddItem "B3"
End If
If Combo1.Text = "C" Then
Combo2.Clear
Combo2.AddItem "C1"
Combo2.AddItem "C2"
Combo2.AddItem "C3"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
不用另外设置按钮,选择完combo1后,combo2的内容就直接变了。如果另外添加按钮,太罗嗦了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我想你想要的是数据关联
建一个窗体
局部变量--字典
Dim Dic As Object
Private Sub ComboBox1_Change()
ComboBox2.List = Split(Dic(ComboBox1.Text), ",")
ComboBox2.ListIndex = 0
End Sub
'窗口初始化,载入关联值
Private Sub UserForm_Initialize()
Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add "A", "A1,A2,A3"
Dic.Add "B", "B1,B2,B3"
Dic.Add "C", "C1,C2,C3"
ComboBox1.List = Dic.keys
ComboBox1.ListIndex = 0
End Sub
建一个窗体
局部变量--字典
Dim Dic As Object
Private Sub ComboBox1_Change()
ComboBox2.List = Split(Dic(ComboBox1.Text), ",")
ComboBox2.ListIndex = 0
End Sub
'窗口初始化,载入关联值
Private Sub UserForm_Initialize()
Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add "A", "A1,A2,A3"
Dic.Add "B", "B1,B2,B3"
Dic.Add "C", "C1,C2,C3"
ComboBox1.List = Dic.keys
ComboBox1.ListIndex = 0
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
If Combo1.Text = "A" Then
Combo2.Clear
Combo2.AddItem "A1"
Combo2.AddItem "A2"
Combo2.AddItem "A3"
End If
If Combo1.Text = "B" Then
Combo2.Clear
Combo2.AddItem "B1"
Combo2.AddItem "B2"
Combo2.AddItem "B3"
End If
If Combo1.Text = "C" Then
Combo2.Clear
Combo2.AddItem "C1"
Combo2.AddItem "C2"
Combo2.AddItem "C3"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
If Combo1.Text = "A" Then
Combo2.Clear
Combo2.AddItem "A1"
Combo2.AddItem "A2"
Combo2.AddItem "A3"
End If
If Combo1.Text = "B" Then
Combo2.Clear
Combo2.AddItem "B1"
Combo2.AddItem "B2"
Combo2.AddItem "B3"
End If
If Combo1.Text = "C" Then
Combo2.Clear
Combo2.AddItem "C1"
Combo2.AddItem "C2"
Combo2.AddItem "C3"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Combo1_Click()
Select Case Combo1.Text
Case "A"
Combo2.Text = "A1"
Case "B"
Combo2.Text = "A2"
Case "C"
Combo2.Text = "A3"
End Select
End Sub
Select Case Combo1.Text
Case "A"
Combo2.Text = "A1"
Case "B"
Combo2.Text = "A2"
Case "C"
Combo2.Text = "A3"
End Select
End Sub
追问
答非所问!继续求解!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询