VB中comboBox的问题,
我创建二个combobox比如说combo1是游戏大区,combo2是游戏服务器我选中combo1中的一个大区,在combo2中出现这个大区下的服务器名字,我该怎么弄,...
我创建二个combobox
比如说combo1是游戏大区,combo2是游戏服务器
我选中combo1中的一个大区,在combo2中出现这个大区下的服务器名字,我该怎么弄, 展开
比如说combo1是游戏大区,combo2是游戏服务器
我选中combo1中的一个大区,在combo2中出现这个大区下的服务器名字,我该怎么弄, 展开
2个回答
展开全部
给你举个例子吧,添加两个combobox,然后粘贴下面的代码就可以达到你的效果,如果有不明白的请百度HI我
Private list(0 To 2, 0 To 2) As String
Private Sub Combo1_Click()
If Combo1.ListIndex >= 0 Then
Combo2.Clear
Dim i As Integer
For i = 0 To 2
If list(Combo1.ListIndex, i) <> "" Then
Combo2.AddItem list(Combo1.ListIndex, i)
End If
Next
End If
End Sub
Private Sub Form_Load()
Dim s() As String
Dim i As Integer
s = Split("服务器1|服务器2|服务器3", "|")
For i = 0 To UBound(s)
list(0, i) = s(i)
Next i
s = Split("服务器4|服务器5|服务器6", "|")
For i = 0 To UBound(s)
list(1, i) = s(i)
Next i
s = Split("服务器7|服务器8|服务器9", "|")
For i = 0 To UBound(s)
list(2, i) = s(i)
Next i
Combo1.AddItem "大区1"
Combo1.AddItem "大区2"
Combo1.AddItem "大区3"
End Sub
Private list(0 To 2, 0 To 2) As String
Private Sub Combo1_Click()
If Combo1.ListIndex >= 0 Then
Combo2.Clear
Dim i As Integer
For i = 0 To 2
If list(Combo1.ListIndex, i) <> "" Then
Combo2.AddItem list(Combo1.ListIndex, i)
End If
Next
End If
End Sub
Private Sub Form_Load()
Dim s() As String
Dim i As Integer
s = Split("服务器1|服务器2|服务器3", "|")
For i = 0 To UBound(s)
list(0, i) = s(i)
Next i
s = Split("服务器4|服务器5|服务器6", "|")
For i = 0 To UBound(s)
list(1, i) = s(i)
Next i
s = Split("服务器7|服务器8|服务器9", "|")
For i = 0 To UBound(s)
list(2, i) = s(i)
Next i
Combo1.AddItem "大区1"
Combo1.AddItem "大区2"
Combo1.AddItem "大区3"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询