I have a single-selection ListView where I always want to keep an item
selected by default. If the user clicks in the empty area below the
items, I want to select the first item.
It appears that when the user selects a new item, two
SelectedIndexChanged events are fired: one with no SelectedItems, and
then one with the new SelectedItem. Because of that, I can't tell if
an event with no selection is because the user clicked outside the
list items (and I should select the first one) or because they
selected another item (and I shouldn't).
Does anyone know a workaround for this?
Jared - 31 Mar 2006 01:56 GMT
From MouseClick event
MyListViewHitTestInfo = ListView1.HitTest(New Point(e.X, e.Y)
if MyListViewHitTestInfo.item is nothing then
me.ListView1.items(0).selected=true
me.ListView1.Select
End If
Should work well with you SIC event as well.
>I have a single-selection ListView where I always want to keep an item
> selected by default. If the user clicks in the empty area below the
[quoted text clipped - 8 lines]
>
> Does anyone know a workaround for this?
Mark Smith - 31 Mar 2006 16:39 GMT
>From MouseClick event
>
[quoted text clipped - 4 lines]
>me.ListView1.Select
>End If
Hi Jared, thanks for the suggestion. Unfortunately, the ListView
doesn't fire a MouseClick event in the area below the items, so it
won't work...
Jared - 31 Mar 2006 21:21 GMT
MouseUp will do ...
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
Dim HTI0 As ListViewHitTestInfo
HTI0 = Me.ListView1.HitTest(New Point(e.X, e.Y))
If HTI0.Item Is Nothing Then
Trace.WriteLine(True)
Else
Trace.WriteLine(False)
End If
End Sub