Help with List view

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • whirl

    Help with List view

    Hello.
    before I paste my code I will try and explain what I am trying to achieve.
    I have loaded a txt file which contains 26,000 items into a listview
    I want to be able to enter some text into a text box and when I press a
    command button it
    Removes all items from the listview that DOES NOT match what I have entered
    in the text box.
    Although the code below works, it is extremely SLOW.
    can anyone help me improve this, (example code would be great)

    Regards
    Ian


    Private Sub cmdok_Click()
    Dim SearchItem As String
    SearchItem = LCase$(Trim$(tx tfind)) 'txtfind is a textbox
    Dim i As Long
    Me.MousePointer = vbHourglass

    For i = listview1.ListI tems.Count - 1 To 0 Step -1
    If i = 0 Then GoTo done
    If InStr(listview1 .ListItems(i), SearchItem) > 0 Then

    Else
    With listview1.ListI tems
    .Remove (i)
    End With
    End If

    Next
    done:
    Me.MousePointer = vbDefault

    End Sub


  • Don@home.com

    #2
    Re: Help with List view

    On Mon, 21 Jul 2003 19:30:37 +0100, "whirl" <whirl@whirl.or g.uk> wrote:
    [color=blue]
    >Hello.
    >before I paste my code I will try and explain what I am trying to achieve.
    >I have loaded a txt file which contains 26,000 items into a listview
    >I want to be able to enter some text into a text box and when I press a
    >command button it
    >Removes all items from the listview that DOES NOT match what I have entered
    >in the text box.
    >Although the code below works, it is extremely SLOW.
    >can anyone help me improve this, (example code would be great)
    >
    >Regards
    >Ian
    >
    >
    >Private Sub cmdok_Click()
    >Dim SearchItem As String
    >SearchItem = LCase$(Trim$(tx tfind)) 'txtfind is a textbox
    >Dim i As Long
    >Me.MousePointe r = vbHourglass
    >[/color]
    Something to try.. Not really sure how it will affect the display
    listview1.visib le = false 'then set it visilble=true on exit
    If that is flaky then you might want to try the LockWindowUpdat e API
    Declare Function LockWindowUpdat e Lib "user32" Alias _
    "LockWindowUpda te" (ByVal hwndLock As Long) As Long
    And call it like
    LockWindowUpdat e me.hwnd
    and on exit
    LockWindowUpdat e 0&

    Control Refreshs are a bugger... LOL
    [color=blue]
    > For i = listview1.ListI tems.Count - 1 To 0 Step -1
    > If i = 0 Then GoTo done
    > If InStr(listview1 .ListItems(i), SearchItem) > 0 Then
    >
    > Else
    > With listview1.ListI tems
    > .Remove (i)
    > End With
    > End If
    >
    >Next
    >done:
    > Me.MousePointer = vbDefault
    >
    >End Sub
    >[/color]

    Have a good day...

    Don

    Comment

    • Dooley

      #3
      Re: Help with List view

      hello, would copying the matching text to another listbox work, I just read
      your post and modified something I have been working on to solve issues for
      others. if not let me know and I will modify it to just delete from the
      listbox in question.


      "whirl" <whirl@whirl.or g.uk> wrote in message
      news:cpfTa.3429 1$Df6.14262@new s-binary.blueyond er.co.uk...[color=blue]
      > Hello.
      > before I paste my code I will try and explain what I am trying to achieve.
      > I have loaded a txt file which contains 26,000 items into a listview
      > I want to be able to enter some text into a text box and when I press a
      > command button it
      > Removes all items from the listview that DOES NOT match what I have[/color]
      entered[color=blue]
      > in the text box.
      > Although the code below works, it is extremely SLOW.
      > can anyone help me improve this, (example code would be great)
      >
      > Regards
      > Ian
      >
      >
      > Private Sub cmdok_Click()
      > Dim SearchItem As String
      > SearchItem = LCase$(Trim$(tx tfind)) 'txtfind is a textbox
      > Dim i As Long
      > Me.MousePointer = vbHourglass
      >
      > For i = listview1.ListI tems.Count - 1 To 0 Step -1
      > If i = 0 Then GoTo done
      > If InStr(listview1 .ListItems(i), SearchItem) > 0 Then
      >
      > Else
      > With listview1.ListI tems
      > .Remove (i)
      > End With
      > End If
      >
      > Next
      > done:
      > Me.MousePointer = vbDefault
      >
      > End Sub
      >
      >[/color]


      Comment

      • David Segall

        #4
        Re: Help with List view

        Posted and emailed:
        "whirl" <whirl@whirl.or g.uk> wrote:
        [color=blue]
        >Hello.
        >before I paste my code I will try and explain what I am trying to achieve.
        >I have loaded a txt file which contains 26,000 items into a listview
        >I want to be able to enter some text into a text box and when I press a
        >command button it
        >Removes all items from the listview that DOES NOT match what I have entered
        >in the text box.
        >Although the code below works, it is extremely SLOW.
        >can anyone help me improve this, (example code would be great)
        >
        >Regards
        >Ian[/color]
        [code snipped]

        In a related competition for speed in comp.lang.basic .visual.misc Dag
        Sunde provided an elegant and very fast solution by using the text
        file ODBC driver and an SQL SELECT statement. In your case you can use
        the same code to (re)populate the listview just by changing the SELECT
        statement. The follow ups provide additional information about setting
        up the ODBC driver. Here is the link to his post
        http://www.google.com. au/groups?hl=en&lr =&ie=UTF-8&oe=UTF-8&frame=right&r num=31&thl=1135 047719,11349669 79,1134770359,1 134751242,11347 39727,113473728 1,1134658165,11 34622808,113452 1208,1134510182 ,1134484638,113 4439555&seekm=Q XYL9.3785%24ZL2 .337240%40julie tt.dax.net#link 32

        Comment

        • whirl

          #5
          Re: Help with List view

          Many thanks for all those who gave me the advice i was looking for

          Cheers


          "whirl" <whirl@whirl.or g.uk> wrote in message
          news:cpfTa.3429 1$Df6.14262@new s-binary.blueyond er.co.uk...[color=blue]
          > Hello.
          > before I paste my code I will try and explain what I am trying to achieve.
          > I have loaded a txt file which contains 26,000 items into a listview
          > I want to be able to enter some text into a text box and when I press a
          > command button it
          > Removes all items from the listview that DOES NOT match what I have[/color]
          entered[color=blue]
          > in the text box.
          > Although the code below works, it is extremely SLOW.
          > can anyone help me improve this, (example code would be great)
          >
          > Regards
          > Ian
          >
          >
          > Private Sub cmdok_Click()
          > Dim SearchItem As String
          > SearchItem = LCase$(Trim$(tx tfind)) 'txtfind is a textbox
          > Dim i As Long
          > Me.MousePointer = vbHourglass
          >
          > For i = listview1.ListI tems.Count - 1 To 0 Step -1
          > If i = 0 Then GoTo done
          > If InStr(listview1 .ListItems(i), SearchItem) > 0 Then
          >
          > Else
          > With listview1.ListI tems
          > .Remove (i)
          > End With
          > End If
          >
          > Next
          > done:
          > Me.MousePointer = vbDefault
          >
          > End Sub
          >
          >[/color]


          Comment

          Working...