-
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?
-
You can try the EnsureVisible property on the listitem object
-
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.
-
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.
-
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.
-
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