views:

284

answers:

2

I have a ListView with the Activation property with HotTracking. There appears to be about a 2 second delay between when the user clicks the item and the event fires. Is there a way to get the event to fire immediately upon the user click?

A: 

Yes, use the SelectedIndexChanged event instead!

Thought of that, but it won't work if the item is already selected.
Adam Ruth
+1  A: 

I have found no way to change this delay, it's a built-in setting.

Problem is, the MouseDown event actually has a delayed reaction, only setting the SelectedItems property after it has fired.

You have to do this manually: use the MouseClick event. This will fire if an item is clicked, even if its an already selected item. It will not fire when empty space is clicked.

Private Sub list_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles list.MouseClick
 Dim item As ListViewItem = list.GetItemAt(e.X, e.Y)
 If Not IsNothing(item) Then
  do your stuff here
 End If
End Sub

You can simulate hot tracking by handling this event

Private Sub list_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles list.MouseMove
 Dim item As ListViewItem = list.GetItemAt(e.X, e.Y)
 If Not IsNothing(item) Then
  list.SelectedItems.Clear()
  item.Selected = True
 End If
End Sub
Wez