all groups > vb.net controls > december 2005 >
You're in the

vb.net controls

group:

Listview control and Selecting items using down arrow key


Listview control and Selecting items using down arrow key gv
12/7/2005 3:51:54 PM
vb.net controls: Hi

This will not work nor do I get an error?

Will not set the first item when the selected item gets to the last one by
pressing the down arrow
key.

Private Sub ListView2_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListView2.KeyDown

If ListView2.SelectedItems(0).Index = (ListView2.Items.Count - 1)
And e.KeyCode = Keys.Down Then
ListView2.Items(0).Selected = True
ListView2.Select()
e.Handled = True

ElseIf ListView2.SelectedItems(0).Index = 0 And e.KeyCode = Keys.Up
Then
ListView2.Items(ListView2.Items.Count - 1).Selected = True
ListView2.Select()
e.Handled = True

End If

End Sub

thanks
Gerry

Re: Listview control and Selecting items using down arrow key gv
12/7/2005 5:51:01 PM
Hi all,

I got the key arrow down to work right but the key up still doesn't? I
tappears to
focus on the correct one but then I cannot move up anymore with the up
arrow.
The focus is not working correctly.


Private Sub ListView2_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListView2.KeyDown

If ListView2.SelectedItems(0).Index = (ListView2.Items.Count - 1)
And e.KeyCode = Keys.Down Then
ListView2.Items(0).Focused = True
ListView2.Items(0).Selected = True
ListView2.Items(0).EnsureVisible()
e.Handled = True
End If

If ListView2.SelectedItems(0).Index = 0 And e.KeyCode = Keys.Up Then
ListView2.Items(ListView2.Items.Count - 1).Focused = True
ListView2.Items(ListView2.Items.Count - 1).Selected = True
ListView2.Items(ListView2.Items.Count - 1).EnsureVisible()
e.Handled = True
End If

End Sub



[quoted text, click to view]

Re: Listview control and Selecting items using down arrow key gv
12/7/2005 6:01:07 PM
OK THIS WORKS! why not documented better? Is there a simplier way to do
this?

Private Sub ListView2_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ListView2.KeyDown

If ListView2.SelectedItems(0).Index = (ListView2.Items.Count - 1)
And e.KeyCode = Keys.Down Then
ListView2.SelectedItems.Clear()
ListView2.Items(0).Focused = True
ListView2.Items(0).Selected = True
ListView2.Items(0).EnsureVisible()
e.Handled = True
ElseIf ListView2.SelectedItems(0).Index = 0 And e.KeyCode = Keys.Up
Then
ListView2.SelectedItems.Clear()
ListView2.Items(ListView2.Items.Count - 1).Focused = True
ListView2.Items(ListView2.Items.Count - 1).Selected = True
ListView2.Items(ListView2.Items.Count - 1).EnsureVisible()
e.Handled = True
End If

thanks
Gerry



End Sub
[quoted text, click to view]

AddThis Social Bookmark Button