我需要在表單中添加可變數量的ComboBoxes,之後我需要從ComboBoxes讀取輸入。在窗體中動態添加多個組合框並讀取添加的組合框的輸入?
我有這樣的代碼 -
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim n As Integer = Int(QsnNo.Text)
Dim i As Integer = 0
Do While i <= n
ComboGen(i)
i = i + 1
Loop
End Sub
Public Function ComboGen(ByVal n As Integer)
Dim newCombo As New ComboBox
With newCombo
.Name = "MyComboBox" & n.ToString
.Left = 10
.Top = 10 + (20 * n) + 20
.Width = 70
.Height = 20
.Items.Add("A")
.Items.Add("B")
.Visible = True
End With
Me.Controls.Add(newCombo)
Return 0
End Function
而且我可以添加組合框。但是當我點擊Button2時,我想在稍後閱讀組合框的輸入。我不能。我怎樣才能做到這一點?
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
TextBox1.Text = MyComboBox1.selectedItem
End Sub
我需要這樣的輸出。