我正在尝试以编程方式将未指定数量的新用户控件添加到表单中。每次在包含在 UserControl 中的 ComboBox 中选择一个条目时,都会添加一个。
问题是,SelectedIndexChanged 事件完全不规律地触发。有时是两次,有时是 3 次,等等,但绝不是一次。无论我将组合框的 SelectedIndex 设置为 -1 多少次,它都会至少触发一次,且 SelectedIndex 为 0。有时 Itemselected 事件会在 SelectedIndexChanged 事件之间触发多次。
InvoiceEntry.vb 片段:
Public Event ItemSelected As EventHandler
Private Sub cboItem_SelectedIndexChanged(sender As System.Object, _
e As System.EventArgs) Handles cboItem.SelectedIndexChanged
RaiseEvent ItemSelected(Me, EventArgs.Empty)
End Sub
发票.vb 片段:
Private numEntries As Integer = 1
Public Sub invEntry1_ItemSelected() Handles invEntry1.ItemSelected
numEntries += 1
Dim newEntry As InvoiceEntry = invEntry1
Dim pt As Point = newEntry.Location
pt.Y += 30
newEntry.Location = pt
newEntry.Name = "invEntry" + numEntries.ToString
pnlEntries.Controls.Add(newEntry)
结束子
我完全不知道出了什么问题。如果您需要更多信息,请告诉我,因为我将监控此线程,直到我或其他人弄清楚为止。