Vb.net 组合框功能
我的visual basic中有4个组合框; ComboBox1有3项:车辆、摩托车、无 ComboBox2有4个项目:运动自行车、休闲自行车和运动汽车、休闲汽车 组合框3 组合框4 我需要一个代码,可以让我执行以下操作:Vb.net 组合框功能,vb.net,Vb.net,我的visual basic中有4个组合框; ComboBox1有3项:车辆、摩托车、无 ComboBox2有4个项目:运动自行车、休闲自行车和运动汽车、休闲汽车 组合框3 组合框4 我需要一个代码,可以让我执行以下操作: 使组合框2、3、4不可见,直到我在组合框1上进行选择,即我将选择vehicle,然后继续选择sportscar,同时组合框3和4不可见。简而言之,下一个组合框仅在对上一个组合框进行选择后出现 在组合框1上,如果选择了“无”,则其他2,3,4将保持无敌状态 在设计器文件中,将V
在设计器文件中,将Visible属性2、3和4设置为false 然后在代码文件中使用以下代码:
Private子Combox1\u SelectedIndexChanged(发送方作为对象,e作为事件参数)处理Combox1.SelectedIndexChanged
Dim showComboBox=非字符串。isNull或空白(ComboBox1.Text)以及ComboBox1.Text“无”
ComboBox2.Visible=showComboBox
ComboBox3.Visible=showcombox3
ComboBox4.Visible=showcombox4
端接头
如果
ComboBox1
的文本不是空字符串且不是“无”,则将布尔变量设置为等于。然后将其他组合框控件的Visible属性设置为结果。在forms Load事件中,需要将组合框2、3和4设置为Visible=False。然后在ComboBox1\u SelectedIndexChanged事件中,您可以将Combox2更改为visible=True,然后对每个进程执行相同的操作。代码如下所示。您还需要决定如何重置上一个框。换句话说,如果在combobox1中从摩托车更改为无,是否希望Combox2、3和4再次变为不可见
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox2.Visible = False
ComboBox3.Visible = False
ComboBox4.Visible = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem="None" then
ComboBox2.Visible=False
ComboBox3.Visible=False
ComboBox4.Visible=False
Else
ComboBox2.Visible = True
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox3.Visible = True
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox4.Visible = True
End Sub
End Class
非常感谢你抽出时间来帮助我。好的,是的,如果我选择“无”,我希望组合框2,3,4不显示我在回答中更改了ComboBox1的代码\u SelectedIndexChanged事件,以显示如果ComboBox1更改为“无”,如何使其他框不可见。