.net Can';除非使用计时器,否则不要在运行时选择动态创建的组合框的值
我在运行时创建了N个combobox,并将它们绑定到不同的数据表,当我尝试在运行时选择它们的值,但它们好像还没有加载任何值时,我只能通过使用触发另一个事件的计时器来完成此任务,但我不能这样做。 如果有帮助,可以在自定义类面板内创建组合框 Edit1:也尝试使用委托 工作 不起作用.net Can';除非使用计时器,否则不要在运行时选择动态创建的组合框的值,.net,vb.net,combobox,.net,Vb.net,Combobox,我在运行时创建了N个combobox,并将它们绑定到不同的数据表,当我尝试在运行时选择它们的值,但它们好像还没有加载任何值时,我只能通过使用触发另一个事件的计时器来完成此任务,但我不能这样做。 如果有帮助,可以在自定义类面板内创建组合框 Edit1:也尝试使用委托 工作 不起作用 cbodescription.Focus() For i As Integer = 0 To mLista.Count - 1 Dim Txtbox As New TextBox
cbodescription.Focus()
For i As Integer = 0 To mLista.Count - 1
Dim Txtbox As New TextBox
Txtbox.Tag = i
Txtbox.Text = mLista(i).Codice.ToString.Trim
Dim o As New KeyPressEventArgs(Microsoft.VisualBasic.ChrW(Keys.Enter))
Panel_onTxtCodiceKeyPress(Txtbox, o)
Next
按键事件
Private Sub Panel_onTxtCodiceKeyPress(sender As Object, e As KeyPressEventArgs) Handles PanelSF.onTxtCodiceKeyPress
Dim Tag As Integer = DirectCast(sender, TextBox).Tag
Dim Value As String = CType(sender, TextBox).Text
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
Dim Tipo As Integer = Panel.GetCboType(Tag)
If ArticoloExist(Tipo, Value) = True Then
Panel.ChangeDisplayMemberByName(Tag, mItemName)
End If
mItemName = ""
End If
ChangeDisplayMemberByName
Public Sub ChangeDisplayMemberByName(Tag As Integer, Nome As String)
Dim Cbo As ComboBox
For Each Ingrediente As ClassIngredienteRicetta In ListaIngredienti
If Ingrediente.Numero() = Tag Then
Ingrediente.Descrizione = Nome
End If
Next
For Each Control As Control In Me.Controls
If TypeOf Control Is ComboBox Then
If Control.Name = "CboArticoli" & Tag Then
Cbo = Control
Cbo.SelectedIndex = Cbo.FindString(Nome)
Exit Sub
End If
End If
Next
End Sub
关于如何完成该任务的任何建议?通过在表单中使用委托来解决。加载事件
mLista
或mlistingredienti
?mLista是我定义的一个类的列表,其中每个项包含每个项的所有信息,mLista.Codice包含Combobox.ValueMember和mLista.DescriptionOne包含Combobox.DislayMember,选择传递值的值或搜索字符串将返回Nothing您将“不工作”的代码放在哪里了?我已将其放在Public Sub New()中,但我已解决,谢谢您的回答
Public Sub ChangeDisplayMemberByName(Tag As Integer, Nome As String)
Dim Cbo As ComboBox
For Each Ingrediente As ClassIngredienteRicetta In ListaIngredienti
If Ingrediente.Numero() = Tag Then
Ingrediente.Descrizione = Nome
End If
Next
For Each Control As Control In Me.Controls
If TypeOf Control Is ComboBox Then
If Control.Name = "CboArticoli" & Tag Then
Cbo = Control
Cbo.SelectedIndex = Cbo.FindString(Nome)
Exit Sub
End If
End If
Next
End Sub