在列表框中进行select时更改文本框

我有一个用户forms的2个列表框和两个相应的文本框。 当我在列表框中进行select时,我希望相应的文本框更新为具有相同的值。 我已经安排了这样的function来完成我的用户forms:

Private Sub ListBox1_Click() TextBox1.Value = TopSelectedValue(ListBox1) End Sub Private Sub ListBox2_Click() TextBox2.Value = TopSelectedValue(ListBox2) End Sub Function TopSelectedValue(myBox As MSForms.ListBox) As String 'Finds value of first selected item in ListBox Select Case myBox.MultiSelect Case fmMultiSelectSingle TopSelectedValue = myBox.Value Case fmMultiSelectMulti, fmMultiSelectExtended TopSelectedValue = myBox.List(TopSelectedIndex(myBox)) End Select End Function Function TopSelectedIndex(myBox As MSForms.ListBox) As Integer Dim k As Integer Select Case myBox.MultiSelect Case fmMultiSelectSingle TopSelectedIndex = myBox.ListIndex Case fmMultiSelectMulti, fmMultiSelectExtended For k = 0 To myBox.ListCount - 1 If myBox.Selected(k) = True Then TopSelectedIndex = k Exit Function End If Next k TopSelectedIndex = -1 End Select End Function 

注意: ListBox1是单选, ListBox2是多选的。

问题是,对于ListBox1ListBox1更改时cue上的TextBox1更新),一切正常, ListBox2select或更改ListBox2时, TextBox2什么也没有发生。

我试图通过添加这种types的代码来重置select来修复它,但是这也失败了:

 Private Sub ListBox1_Click() TextBox1.Value = TopSelectedValue(ListBox1) Dim C As MSForms.Control For Each C In Me.Controls If TypeOf C Is MSForms.ListBox Then C.ListIndex = -1 Next C End Sub 

为什么列表框/文本框之间的关系不是以相同的方式performance的,我能做些什么来解决这个问题?