我需要在表单中添加可变数量的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
我需要这样的输出。