我有一个ComboBox
数据绑定到ObservableCollection
strings
。 ComboBox
也是可编辑的,因此您可以输入自己的值或从列表中选择一个。我遇到的问题是SelectedItem
的索引似乎是您在ComboBox
中输入自己的值时选择的最后一项的索引,但是当您输入时它是-1将IsTextSearchEnabled
设置为true。
问题是,如果某人输入了自己的值,然后决定选择之前选择的ComboBox
上的项目,则索引不会更改,因此SelectionChange
事件不会火了。在这种情况下,如何才能举办活动?
答案 0 :(得分:1)
测试一下...... 我希望这会有所帮助:
Dim oldSEL As String = ""
'always checking while you move your mouse over the combobox (when altering selection) and using the keyboard to (alter selection)
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.MouseMove, ComboBox1.KeyPress
Dim currentSEL As String = ComboBox1.SelectedText
If Not (oldSEL = "" And currentSEL = oldSEL) Then
fire()
oldSEL = currentSEL
End If
End Sub
Private Sub fire()
Trace.Write("text selected changed")
End Sub
您应该根据自己的喜好更改所有Combobox1。