我必须向usercontrol(VB.NET)添加一组类似控件的变量。 上下文: 对于iceskate竞赛,我必须创建一个包含n行的用户表单(n =参与者数量)。在每一行我必须添加m组合框和m文本框(m =元素数)
我在下面的代码中执行此操作,但对于组合框,当我更改一个时,所有其他代码保留相同的选定项。这与文本框不同。我不明白为什么。
有什么想法吗?
For I = 1 To nbrelements
Dim cmbelem As ComboBox
cmbelem = New ComboBox()
cmbelem.DataSource = tblelements
cmbelem.ValueMember = "Code"
cmbelem.DisplayMember = "Code"
cmbelem.Name = "Elem" & I & "/" & dtr.Item("idpatineur")
cmbelem.Height = 20
cmbelem.Width = 60
PosHor += 65
cmbelem.Location = new Point(PosHor,posligne)
Fempty.Controls.Add(cmbelem)
cmbelem = nothing
Dim txtElem As TextBox
txtElem = New TextBox()
txtElem.Name = "txt" & I & "/" & dtr.Item("idpatineur")
txtElem.Text = "0"
txtElem.Height = 20
txtElem.Width = 20
PosHor += 65
txtelem.Location = new Point(PosHor,posligne)
Fempty.Controls.Add(TxtElem)
Next