954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Listview Keydom go to top?

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

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 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

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 

ListBox1.SelectedItem = ListBox1.Items(0)

Property SelectedItems is ReadOnly

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Check this Out , May be this will help you :)

Attachments Calculator.zip (63.5KB)
waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 

calculator is listbox
not listview

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 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?

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

keydown can work after listproduct have one click mouse

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Now which ListView isNot responding properly? ListGroup or ListProduct?

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

"keydown" on which ListView?

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

listproduct

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

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
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 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?

codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

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

LearnVBnet
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: