vb.net – 如何在运行时更改列表框中的选定项目文本?
发布时间:2020-12-17 07:17:19 所属栏目:百科 来源:网络整理
导读:我尝试使用这样的代码: 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) = Text
我尝试使用这样的代码:
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 确保检查ListBox中是否实际选择了一个项目: If ListBox1.SelectedIndex > -1 Then ListBox1.Items(ListBox1.SelectedIndex) = TextBox1.Text End If (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |