Solved

Jump to listview1 item by pressing a keyboard letter

Posted on 2004-08-17
7
304 Views
Last Modified: 2010-04-17
I would like to find out if I can jump to specific lines on a listview by pressing the first letter of the text (as you can when using a list).

Specifically, the text is in the subitem(3) area of the listview.

Can someone provide me with a working example. or let me know if it is even possible?
0
Comment
Question by:robbperk
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Expert Comment

by:pillbug22
ID: 11823738
0
 
LVL 6

Expert Comment

by:pillbug22
ID: 11823756
Of course, I was assuming this is for a web page - if it's not, then let us know and we'll work out something else.

For a windows form, you'd want the KeyPress event for the ListBox (or wherever your user is typing the letter)
0
 

Expert Comment

by:Delian
ID: 11824820
Which programming language are you using?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:robbperk
ID: 11824995
Sorry folks.  Should've have mentioned, this is a vb6 app.
0
 

Author Comment

by:robbperk
ID: 11837945
Guess I need to increase the point value.
REMEMBER, this is a VB6 question (my apologise for leaving that out before).

Please help me out.
0
 

Expert Comment

by:much2k3
ID: 11838933
Hi. Am charles

Put a listview on a form and one textbox where you will type the text to search.

Paste the code below. and run the project


Dim ItmX As ListItem
Private Sub Form_Load()
Dim iCount As Long
With ListView1
    .ColumnHeaders.Add , , "Colum1", .Width / 3
    .ColumnHeaders.Add , , "Colum2", .Width / 3
    .ColumnHeaders.Add , , "Colum3", .Width / 3
    .HideSelection = False
    .View = lvwReport
    .FullRowSelect = True
    .GridLines = True
End With
     For iCount = 1 To 100
        Set ItmX = ListView1.ListItems.Add(, , iCount)
             ItmX.SubItems(1) = iCount + 1
             ItmX.SubItems(2) = iCount + 2
    Next iCount
End Sub

Private Sub Text1_Change()
Dim sItemtoFind As String, iCount As Long
 For iCount = 1 To ListView1.ListItems.Count
    Set ItmX = ListView1.ListItems(iCount)
        If LCase(Text1.Text) = LCase(Left(ItmX.SubItems(2), Len(Text1.Text))) Then
            ListView1.SelectedItem = ItmX
            ListView1.SelectedItem.EnsureVisible
        End If
Next iCount

End Sub
0
 

Accepted Solution

by:
much2k3 earned 75 total points
ID: 11840972
Put a listview on a form and one textbox where you will type the text to search.
'//Some corrections to the previous code
Paste the code below. and run the project


Dim ItmX As ListItem
Private Sub Form_Load()
Dim iCount As Long
With ListView1
    .ColumnHeaders.Add , , "Colum1", .Width / 3
    .ColumnHeaders.Add , , "Colum2", .Width / 3
    .ColumnHeaders.Add , , "Colum3", .Width / 3
    .HideSelection = False
    .View = lvwReport
    .FullRowSelect = True
    .GridLines = True
End With
     For iCount = 1 To 100
        Set ItmX = ListView1.ListItems.Add(, , iCount)
             ItmX.SubItems(1) = iCount + 1
             ItmX.SubItems(2) = iCount + 2
    Next iCount
End Sub

Private Sub Text1_Change()
Dim sItemtoFind As String, iCount As Long
 For iCount = 1 To ListView1.ListItems.Count
    Set ItmX = ListView1.ListItems(iCount)
        If LCase(Text1.Text) = LCase(Left(ItmX.SubItems(2), Len(Text1.Text))) Then
            ListView1.SelectedItem = ItmX
            ListView1.SelectedItem.EnsureVisible
            exit for '//To terminate the loop once item is found
        End If
Next iCount

End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now