Results 1 to 6 of 6

Thread: Loading Listview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100

    Unhappy

    I have a form with a textbox and listview control on it.
    My problem is, when I load the listview and I type any text
    in the textbox, the selected item is way down the bottom of the listview.
    I would like when the user types, the selected text is at the top,
    or when the user types and presses the enter key, the listview is loaded & sorted by the text in the textbox.
    How do I do that?

  2. #2
    Guest
    You can try the EnsureVisible property on the listitem object

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    I already have the EnsureVisible property in my code, but the problem is NOT my seeing the selected item, but having
    the selected item as the first item in the listview.

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here's a little example on how to do it:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Dim itmSelectedItem As ListItem
        Dim lngRet As Long
        
        If KeyAscii = 13 Then
            Set itmSelectedItem = ListView1.FindItem(Text1.Text)
            
            If itmSelectedItem Is Nothing Then Exit Sub
            
            ListView1.SetFocus
            itmSelectedItem.EnsureVisible
            itmSelectedItem.Selected = True
        End If
    End Sub
    Type text in the textbox and press Enter.....If the item is found, then the item will be highlighted.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    Thanks gentlemen, but my problem is not with the highlighted
    item, but with the listview loaded & sorted by the text IN
    the textbox.
    For e.g, if I have 7 items in the listview, and I type
    "Good", the FIRST item at the TOP of the listview, should be
    "Good", or the nearest item to it.

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Serge,

    Your search code works great! It was just what I have been looking for.. Now, to take it one step further, I would like to allow "wildcard" search capability such as Window's Explorer 'Find Files' utility...

    My idea would be to place a Seach button on the form which has the populated ListView. When you hit the button, a new form pops up which has a text box and a listview. When loaded, the Listview would NOT be populated yet.. The user would enter text to search for. When they hit the Find button, the listview would then be populated with anything that matches the user's input.

    So for example, if the user entered Bl and the original listview had:

    Blue Car
    Red Car
    Blue Truck
    Red Truck

    The listview would be populated with only Blue Car and Blue Truck which are the only items which included "Bl"...

    Any idea on how to accomplish this?

    Any help would be appreciated..

    Dan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width