0

I have Listview1 and listview2
After from listview1 focus to listview2
ex: row 20

keydown listview2 not go to row 21
but go to row 1, also keyUp not go to row 19 but go to row 1

any one can help, what to do

Thanks

3
Contributors
14
Replies
15
Views
5 Years
Discussion Span
Last Post by LearnVBnet
Featured Replies
  • See if this helps. [CODE] Private Sub _ListProduct_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListProduct.KeyDown With CType(sender, ListView) If Not .Items.Count = 0 Then .MultiSelect = False e.Handled = True '// block default handling. Select Case e.KeyCode Case Keys.Up .Items(0).Selected = True '// select first item. Case Keys.Down … Read More

0

try this code

'use this code on the keydown event of the listbox
If e.KeyData = Keys.Down Then
            ListBox1.SelectedItem = ListBox1.Items(0)
        End If
        If e.KeyData = Keys.Up Then
            ListBox1.SelectedItem = ListBox1.Items(0)
        End If

Hope this helps you

Regards

0

ListBox1.SelectedItem = ListBox1.Items(0)

Property SelectedItems is ReadOnly

0

Not quite clear on your question.
Are you using the KeyUp/KeyDown Events for the ListView or are you referring to the Up/Down arrow keys on your keyboard?

0

Private Sub ListGroup_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ListGroup.KeyPress
If Not ListGroup.SelectedItems.Count = 0 Then
With ListGroup.SelectedItems(0)
Dim foundItem As ListViewItem = ListProduct.FindItemWithText(.Text, True, 0, True)

If foundItem IsNot Nothing Then
ListProduct.MultiSelect = False
ListProduct.TopItem = foundItem
foundItem.Selected = True
ListProduct.Select()
ListProduct.Focus()

End If
End With
End If
End Sub

1

See if this helps.

Private Sub _ListProduct_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListProduct.KeyDown
        With CType(sender, ListView)
            If Not .Items.Count = 0 Then
                .MultiSelect = False
                e.Handled = True '// block default handling.
                Select Case e.KeyCode
                    Case Keys.Up
                        .Items(0).Selected = True '// select first item.
                    Case Keys.Down
                        .Items(.Items.Count - 1).Selected = True '// select last item.
                End Select
                .SelectedItems(0).EnsureVisible() '// make sure that item is visible once selected.
                .HideSelection = False '// keep cute highlight on item.
            End If
        End With
    End Sub
0

Now keydown from keyboard can down but to last row not to row 21
keyup and keydown only go to first row and lastrow....

0

keydown listview2 not go to row 21
but go to row 1, also keyUp not go to row 19 but go to row 1

any one can help, what to do

Is there still an issue?

0

Private Sub ListProduct_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListProduct.ItemSelectionChanged
ListProduct.FullRowSelect = True
ListProduct.HideSelection = False
If Not ListProduct.SelectedItems.Count = 0 Then
Dim lvi As ListViewItem
For Each lvi In ListProduct.SelectedItems
lvi.Focused = True '/// highlight any selected items.
Next
End If
End Sub

Solved... thanks codeorder

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.