Results 1 to 11 of 11

Thread: [RESOLVED] Find Data in Listview VB 6.0

  1. #1

    Thread Starter
    Junior Member ronaldgie's Avatar
    Join Date
    May 2011
    Location
    KARAWANG
    Posts
    24

    Resolved [RESOLVED] Find Data in Listview VB 6.0

    anyone can help me
    how to find data in listview
    at the time in the textbox enter the letter "J" in the listview will display the data beginning with the letter "J".

    Please help me
    Thankyou


    Screenshot
    Name:  Untitled-2.jpg
Views: 1049
Size:  16.3 KB
    Press any key to continue, where's the any key?

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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.



  3. #3
    Hyperactive Member Daniel Duta's Avatar
    Join Date
    Feb 2011
    Location
    Bucharest, Romania
    Posts
    397

    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

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member ronaldgie's Avatar
    Join Date
    May 2011
    Location
    KARAWANG
    Posts
    24

    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?

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Find Data in Listview VB 6.0

    Quote Originally Posted by ronaldgie View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Junior Member ronaldgie's Avatar
    Join Date
    May 2011
    Location
    KARAWANG
    Posts
    24

    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?

  8. #8

    Thread Starter
    Junior Member ronaldgie's Avatar
    Join Date
    May 2011
    Location
    KARAWANG
    Posts
    24

    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?

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Junior Member ronaldgie's Avatar
    Join Date
    May 2011
    Location
    KARAWANG
    Posts
    24

    Re: Find Data in Listview VB 6.0

    problem solved.

    Thank you very much LaVolpe and the other on your time.
    Press any key to continue, where's the any key?

  11. #11
    Member
    Join Date
    Jan 2011
    Posts
    45

    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
  •  



Click Here to Expand Forum to Full Width