-
Feb 28th, 2015, 02:01 PM
#1
Thread Starter
Junior Member
-
Feb 28th, 2015, 02:31 PM
#2
Re: Find Data in Listview VB 6.0
Try this
Code:
Private Sub Text1_Change()
Dim lvi As ListItem
Set lvi = ListView1.FindItem(Text1.Text)
If Not lvi Is Nothing Then
lvi.Selected = True
lvi.EnsureVisible
ListView1.SetFocus
End If
End Sub
It's highlight first founded item.
-
Feb 28th, 2015, 03:12 PM
#3
Hyperactive Member
Re: Find Data in Listview VB 6.0
Maybe something like this :
Code:
Private Sub Text1_Change()
If Len(LTrim(Text1.Text)) = 1 Then
Call FilterList(LTrim(Text1.Text))
End If
End Sub
-
Feb 28th, 2015, 05:19 PM
#4
Re: Find Data in Listview VB 6.0
The ListView control does not have a filter method; however, the API version does. Typically, when I want a search/filter property in a listview, I'll have a 'find first', 'find next' & 'find previous' button/menu. "Find Previous" is a bit harder, but find first/next simply requires setting the starting index in the ListView.Find function. Look at the documentation for the ListView Find function.
If wanting to display only the matches found so far, a separate list will be needed and you'll purge that list, then re-populate it with the search results from the listview, if any.
-
Mar 2nd, 2015, 08:37 PM
#5
Thread Starter
Junior Member
Re: Find Data in Listview VB 6.0
thank LaVolpe
I have solved the problem. but why in the search results at the time of the search textbox to edit it in the empty project so it hangs.
Press any key to continue, where's the any key?
-
Mar 3rd, 2015, 11:29 AM
#6
Re: Find Data in Listview VB 6.0
Originally Posted by ronaldgie
thank LaVolpe
I have solved the problem. but why in the search results at the time of the search textbox to edit it in the empty project so it hangs.
Without seeing your search routine, no way of knowing. My guess is that you are experiencing an infinite loop.
-
Mar 9th, 2015, 01:53 AM
#7
Thread Starter
Junior Member
Re: Find Data in Listview VB 6.0
hi LaVolpe, thanks for the response.
The problem I found
after updating the data, the form becomes hangs when textbox 'cari nama obat' in the clear
Code:
Public Sub CariObat()
On Error Resume Next
lstObat.ListItems.Clear
If RS.State <> 0 Then RS.Close
RS.Open "SELECT * FROM Table_Obat where fNama_Obat like '%" & Trim(txtCariObat) & "%'", CN, 3, 3
While RS.EOF = False
Set mrow = lstObat.ListItems.Add(, , RS.Fields("fNama_Obat"))
mrow.SubItems(1) = RS.Fields("fQty_Obat")
mrow.SubItems(2) = RS.Fields("fSatuan_Barang")
mrow.SubItems(3) = RS.Fields("fHarga_Satuan")
RS.MoveNext
Wend
End Sub
Code:
Private Sub txtCariObat_Change()
Dim msg1 As String
CariObat
If lstObat.ListItems.Count = 0 Then
msg1 = MsgBox("Nama obat yang anda cari tidak di temukan.", vbCritical + vbOKOnly, "Hasil Pencarian") = vbOK
txtCariObat.Text = ""
End If
End Sub
thankyou
Press any key to continue, where's the any key?
-
Mar 9th, 2015, 09:18 AM
#8
Thread Starter
Junior Member
Re: Find Data in Listview VB 6.0
hay 4x2y after I tried the code from you,
Your code runs but only show the results in text2 type on it and I still do not understand to turn it into a character that I enter.
but I thank you for the response.
Press any key to continue, where's the any key?
-
Mar 10th, 2015, 07:57 AM
#9
Re: Find Data in Listview VB 6.0
In post #7, you have a line of code in your Change event: txtCariObat.Text = ""
That line will trigger another Change event. If other code in your project is also changing the text of that textbox, then you can be entering an infinite loop. If that is happening, you can test it by adding a debug.print statement in the Change event and watch your immediate window (Ctrl+G). It will fill up with those print statements.
Are you setting RS to Nothing anywhere after you update? If so, then you will be getting an error in CariObat when referencing the RS variable & if RS is Nothing, then you are entering an infinite loop in the Do While loop. You should remove the On Error Resume Next statement and handle any errors that may occur.
Last edited by LaVolpe; Mar 10th, 2015 at 11:36 AM.
-
Mar 10th, 2015, 09:05 PM
#10
Thread Starter
Junior Member
-
Apr 16th, 2015, 09:03 PM
#11
Member
Re: [RESOLVED] Find Data in Listview VB 6.0
Hi ronaldgie
I am sorry. this thead was resolved, but could you upload the program which your code is running for find data OK.
Thank you so much !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|