我希望能够在我的ListBox上选择一个索引。我的ListBox正在获取取决于所选索引的值,但是当我尝试在列表框中选择一个索引时,它获取值但保持未选中状态。我必须第二次选择索引才能选择它。那是为什么?
这是我在selectedIndexChanged上的代码:
Private Sub listResults_SelectedIndexChanged(sender As Object, e As EventArgs) Handles listResults.SelectedIndexChanged
UpdateContactInformationFromRegistry()
End Sub
UpdateContactInformationFromRegistry()方法:
Private Sub UpdateContactInformationFromRegistry()
Dim contact As Contact = m_contacts.GetContact(listResults.SelectedIndex)
cmbCountries.SelectedIndex = DirectCast(contact.AddressData.Country, Integer)
txtFirstName.Text = contact.FirstName
txtLastName.Text = contact.LastName
txtStreet.Text = contact.AddressData.Street
txtZip.Text = contact.AddressData.ZipCode
txtCity.Text = contact.AddressData.City
End Sub
更新V2
cmbCountries.SelectedIndexChanged事件处理程序
Private Sub cmbCountries_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCountries.SelectedIndexChanged
UpdateGUI()
End Sub
UpdateGUI()方法
Private Sub UpdateGUI()
Dim strContacts() As String = m_contacts.GetContactInfo()
If (strContacts IsNot Nothing) Then
listResults.Items.Clear()
listResults.Items.AddRange(strContacts)
lstCount.Text = listResults.Items.Count.ToString()
End If
End Sub