Results 1 to 4 of 4

Thread: [RESOLVED] Add a filter to a listview

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    35

    Resolved [RESOLVED] Add a filter to a listview

    I have a listview and some data and i would like to use some filters
    For example: Show all records with id>14

    Is there any way to do that?

    Thanks in advance.

  2. #2
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Add a filter to a listview

    Not without custom coding it yourself. Under some cases it may require comparing a value from every single item in the listview and that can be very memory intensive.

    Here is an example
    Code:
    Dim Tmp As Long
    Dim I As Long
    Tmp = ListView1.ListItems.Count
    For I = 1 To Tmp
        If ListView1.ListItems(I).Index > 50 Then
            ListView1.ListItems.Remove I
            I = I - 1
            Tmp = Tmp - 1
            If I = Tmp Then Exit For
        End If
    Next
    Last edited by Mxjerrett; Jun 14th, 2008 at 11:03 PM.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  3. #3
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Add a filter to a listview

    ComCtl32 Header Control has a FilterBar that will allow you to specify filters for individual columns.

    Unfortunately it is not available in the Vb6 ListView.

    http://www.vbaccelerator.com/home/VB...ol/article.asp

    You can add this header control to VbAccelerator sGrid2:
    http://www.vbaccelerator.com/home/vb..._2/article.asp

    Based on column filter, Hide/Show Rows in the Grid.

    Code:
    Public Enum cgFilterFlag
       cgFilterNone
       cgFilterEqual        '=
       cgFilterNotEqual     'Not=
       cgFilterGreaterEqual '>=
       cgFilterGreater      '>
       cgFilterLessEqual    '<=
       cgFilterLess         '<
       cgFilterWildcard     '* and/or ?
    End Enum

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    35

    Re: Add a filter to a listview

    Quote Originally Posted by Mxjerrett
    Not without custom coding it yourself. Under some cases it may require comparing a value from every single item in the listview and that can be very memory intensive.

    Here is an example
    Code:
    Dim Tmp As Long
    Dim I As Long
    Tmp = ListView1.ListItems.Count
    For I = 1 To Tmp
        If ListView1.ListItems(I).Index > 50 Then
            ListView1.ListItems.Remove I
            I = I - 1
            Tmp = Tmp - 1
            If I = Tmp Then Exit For
        End If
    Next
    Cool!
    Thanks!!

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