我在一个winforms后面有这个代码,它只是有一个listbox
作为它的唯一控件:
Imports System.Windows.Forms
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
ListBoxX.Items.Add("hello")
ListBoxX.Items.Add("world")
ListBoxX.Items.Add("foo")
ListBoxX.Items.Add("bar")
End Sub
Private Sub ListBoxX_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBoxX.SelectedIndexChanged
MessageBox.Show("change registered")
End Sub
Private Sub ListBoxX_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles ListBoxX.SelectedValueChanged
MessageBox.Show("change registered X")
End Sub
End Class
如果选择了“hello”然后我点击“hello”然后出现消息框——如果我点击同一个项目,那么SelectedIndex没有改变——那么为什么会触发这个事件呢?如何确保它仅在索引更改时触发?