我在2017年的Visual Basic社区上做了一个程序,它有一个包含各种下拉项目的严重ComboBox。如果组合框有某种组合,则打开此表单。我该如何实现呢?
E.g
ComboBox1项目(字符串)= 1,2,3,4,5
ComboBox2项目(字符串)= a,b,c,d,e
ComboBox 3项(字符串)= A,B,C,D,E
用户选择1,a,A
点击按钮
然后显示表单1
谢谢,我希望它有足够的意义。
我试过的代码是
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.SelectedText.ToString() = "1" And ComboBox2.SelectedText.ToString() = "a" And ComboBox3.SelectedText.ToString() = "A" Then
Then
Form1.Show()
Else
MsgBox("Doesn't Work")
End If
End Sub
End Class
答案 0 :(得分:1)
以下是基于您的案例的示例代码。希望这可以帮到你。
Public Class Form2
Dim selectedItem1, selectedItem2, selectedItem3 As Object
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
showForm1()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
showForm1()
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
showForm1()
End Sub
Private Sub showForm1()
selectedItem1 = ComboBox1.SelectedItem
selectedItem2 = ComboBox2.SelectedItem
selectedItem3 = ComboBox3.SelectedItem
If selectedItem1 Is Nothing OrElse selectedItem2 Is Nothing OrElse selectedItem3 Is Nothing Then
Exit Sub
End If
If ((selectedItem1.ToString() = "1") AndAlso (selectedItem2.ToString() = "a") AndAlso (selectedItem3.ToString() = "A")) Then
Form1.Show()
End If
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' your code to initialize items of ComboBox1, ComboBox2, ComboBox3
End Sub
End Class