请参考下面的代码。
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
nList = ListBox1.SelectedIndex '事先定义的一个全局变量
If nList > -1 Then
Me.TextBox1.Text = ListBox1.Items(nList).ToString
End If
End Sub
'当TextBox1的值修改后按回车键时,保存回ListBox1原位置
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 13 Then
ListBox1.Items(nList) = TextBox1.Text
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
nList = ListBox1.SelectedIndex '事先定义的一个全局变量
If nList > -1 Then
Me.TextBox1.Text = ListBox1.Items(nList).ToString
End If
End Sub
'当TextBox1的值修改后按回车键时,保存回ListBox1原位置
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 13 Then
ListBox1.Items(nList) = TextBox1.Text
End If
End Sub