The
৺.net ListView offers a
৺onSelectedIndexChanged-Event. But if you are selecting another value, the event is fired twice.
Heres a solution for this problem: Create your own ListView-Class, that handles the event vie the appliaction.idle event
The new ListView Class
Public Class myListView
Inherits ListView
Private SelectionDoneHandlerSet As Boolean = False
Public Event selectionChangeFinished()
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
MyBase.OnSelectedIndexChanged(e)
If Not SelectionDoneHandlerSet Then
SelectionDoneHandlerSet = True
AddHandler Application.Idle, New EventHandler(AddressOf Me.ListViewChangeFinished)
End If
End Sub
Private Sub ListViewChangeFinished(ByVal sender As System.Object, ByVal e As System.EventArgs)
SelectionDoneHandlerSet = False
RaiseEvent selectionChangeFinished()
RemoveHandler Application.Idle, New EventHandler(AddressOf Me.ListViewChangeFinished)
End Sub
End Class
The new event
this event is only fired once per selection:
Private Sub MyListView1_SelectedIndexChanged() Handles MyListView1.selectionChangeFinished
If MyListView1.SelectedItems.Count > 0 Then
Me.TextBox1.Enabled = True
Me.TextBox1.Text = MyListView1.SelectedItems(0).Text
Else
Me.TextBox1.Enabled = False
End If
end sub