这是我的代码,用于将组合框阵列添加到组框数组中,然后当选择组合框中的项目时,它会显示辅助组合框
Dim gbQuoteProduct(5) As GroupBox
Dim cmboBoxQuoteProduct(5) As ComboBox
gbQuoteProduct(n) = New GroupBox
Private Sub frmCreateQuote_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With gbQuoteProduct(n)
.Text = ""
.Location = New Point(10, 5 + n * 70)
.Width = 300
.Height = 70
End With
pnlQuoteProducts.Controls.Add(gbQuoteProduct(n))
cmboBoxQuoteProduct(n) = New ComboBox
With cmboBoxQuoteProduct(n)
.Items.Add("A")
.Items.Add("B")
.Items.Add("C")
.Items.Add("D")
.Text = ""
.Location = New Point(60, 15)
End With
gbQuoteProduct(n).Controls.Add(cmboBoxQuoteProduct(n))
AddHandler cmboBoxQuoteProduct(n).SelectedIndexChanged, AddressOf subProducts
End Sub
“子产品”只会生成辅助组合框。
但是如果我从第一个组合框中选择了错误的选项然后尝试更改我的选择,则辅助组合框不会刷新新的组合框。换句话说,第二组合框的选项不会改变以反映第一组合框的变化。
答案 0 :(得分:0)
我这样做并取得了成功。代码在图像下方
Public Class frmQuestion28955485
Dim gbQuoteProduct(5) As GroupBox
Dim cmboBoxQuoteProduct(5) As ComboBox
Dim cmboBoxSubProducts(5) As ComboBox
Dim n As Integer
Private Sub frmCreateQuote_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
n = 1
gbQuoteProduct(n) = New GroupBox
With gbQuoteProduct(n)
.Text = ""
.Location = New Point(10, 5 + n * 70)
.Width = 300
.Height = 70
End With
pnlQuoteProducts.Controls.Add(gbQuoteProduct(n))
cmboBoxQuoteProduct(n) = New ComboBox
With cmboBoxQuoteProduct(n)
.Items.Add("A")
.Items.Add("B")
.Items.Add("C")
.Items.Add("D")
.Text = ""
.Location = New Point(60, 15)
End With
gbQuoteProduct(n).Controls.Add(cmboBoxQuoteProduct(n))
AddHandler cmboBoxQuoteProduct(n).SelectedIndexChanged, AddressOf subProducts
End Sub
Private Sub subProducts(ByVal sender As Object, ByVal e As System.EventArgs)
Try
gbQuoteProduct(n).Controls.Remove(cmboBoxSubProducts(n))
Catch
End Try
cmboBoxSubProducts(n) = New ComboBox
With cmboBoxSubProducts(n)
.Items.Clear()
.Items.Add("You picked " + cmboBoxQuoteProduct(n).Text)
.Text = "You picked " + cmboBoxQuoteProduct(n).Text
.Location = New Point(60, 40)
End With
gbQuoteProduct(n).Controls.Add(cmboBoxSubProducts(n))
End Sub
End Class