0
Dim cbox As New ComboBox     // combo box declaration

        If (cmb_item.SelectedIndex = 0) Then  // option select by other combo box
            Label2.Text = "Enter the ID:"
            txt_id.Visible = True
            cbox.Visible = False
        ElseIf (cmb_item.SelectedIndex = 1) Then
            txt_id.Visible = False
            cbox.Visible = True
            Label2.Text = "Select Department:"
            cbox.Width = 202
            cbox.Height = 23
            cbox.Location = New Point(142, 39)
            gbox2.Controls.Add(cbox)
            cbox.Text = "--Select--"
            cbox.Items.Add("Computer Engineering")
            cbox.Items.Add("Electronics & Communication Engineering")
            cbox.Items.Add("Electrical Engineering")
            cbox.Items.Add("Instrumentation & Control Engineering ")
            cbox.Items.Add("Information Technology")
        ElseIf (cmb_item.SelectedIndex = 2) Then
            Me.Dispose()
        End If

如果选择选项 0 文本框(txt_id)将出现,接下来我将选项更改为 1 组合框(cbox)将出现并隐藏文本框(txt_id)。通过同样的方式我更改选项,当 cbox 获得选择时,它使用现有项目更新 cbox.item。还有其他方法可以避免重复的 cbox 项目吗?

4

0 回答 0