下面是我的代码,将组合框数组添加到groupbox数组中,然后当选择组合框中的项时,它将显示一个辅助组合框。
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其中“子产品”只生成一个二次组合框。
但是,如果我从第一个组合框中选择了错误的选项,然后尝试更改我的选择,则辅助组合框不会刷新新的组合框。换句话说,第二个组合框的选项不会改变以反映第一个组合框中的变化。
发布于 2015-03-10 04:04:45
我做了这件事成功了。代码在图像下面。

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 Classhttps://stackoverflow.com/questions/28955485
复制相似问题