我试过这样的代码:
Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles MyBase.Leave
' This way is not working
ListBox1.SelectedItem = TextBox1.Text
' This is not working too
ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
End Sub
该表格如下所示:
用户在文本框中键入内容时,我需要更改该列表文本。是否可以在运行时执行此操作?
您正在使用表单的离开事件MyBase.Leave
,所以当它触发时,它对您毫无用处。
尝试改用TextBox的TextChanged事件。
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) _
Handles TextBox1.TextChanged
确保检查是否在列表框中实际选择了一个项目:
If ListBox1.SelectedIndex > -1 Then
ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text
End If
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句