maybe there is a better way or api to do what you want, but this woks for me
VB Code:
Dim i As Integer, bfound As Boolean
For i = 1 To lv1.ListItems.Count
lv1.ListItems(i).Selected = False
If Not bfound Then
If LCase(Left(lv1.ListItems(i), Len(tdate(Index)))) = tdate(Index) Then
lv1.ListItems(i).Selected = True
lv1.ListItems(i).EnsureVisible
bfound = True
End If
End If
Next
i put the boolean in as the listview was multi select, put the code in the textbox change event, change the names of you textbox and listview
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
tdate is textbox, (actually an array of text boxes, that's why it has an index),
any textbox will do, just change the name and remove the index part
it just compares the text in the textbox to the items in the listview and selects the first it finds that matches, unselects any others that may have been selected previously, in case of multiple select being enabled (as it is in my project)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
put the code in the textbox change event, change the names of you textbox and listview
if you put the code in the textbox change event, it will work for typing, but also pasting
i tested the code and it worked ok
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
I put the code in the text change event. But as I've said earlier I have a subroutine called on the text change event, which trigger the filtering of the recordset.
It's working fine I just want to add the autocomplete for the textbox.
VB Code:
Private Sub text1_Change()
Dim i As Integer, bfound As Boolean
' my filter
LookUp text1
'westconn1's code
For i = 1 To lv1.ListItems.Count
lv1.ListItems(i).Selected = False
If Not bfound Then
If LCase(Left(lv1.ListItems(i), Len(text1))) = text1 Then
lv1.ListItems(i).Selected = True
lv1.ListItems(i).EnsureVisible
bfound = True
End If
End If
Next
End Sub
There must be a conflict somewhere. Sorry guys i'm a noob.
This is another way to do it. Its from API guide with some additions... If you want the full code its under "SendMessage", the first example.
the text box is Text1, Listbox is List1
VB Code:
'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Mmm... It should work fine...
I've attached the whole example anyway in case i might have missed something.
Also i should note that it only searches the first column, so it won't check for the other subitems. If You want it to check them as well, then your gonna have to change the FindItem function.
Ok thanks once again. I'm really stressed out lately. I've been doing programming for the past two months straight and now I'm braindead. Maybe I should take a break.
Anyway thanks Andrew!
---edit-----
My Bad. HideSelection was checked!!! That's IT.
Last edited by zynder; Nov 20th, 2006 at 12:36 AM.
i see it is a lot easier to do stuff in the list box than the way i was doing it, but i can't get you code to work right for filling the textbox and doing the selected text, this is because the sub is called recursivly when the text is changed within the sub and even when the the text is not changed within it, the sub runs twice if it overwrites selected text
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Exactly! Hey Westconn1, your code actually works now that I unchecked the HideSelection.
LOL. I wasn't paying attention to the properties so I ended up changing some of the codes, which I doubted to be causing the problem. It's okay I have my backup.