Results 1 to 3 of 3

Thread: Searching database with partial name

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    13

    Searching database with partial name

    Is there a way to search through a listview using only part of a search name?

    For example, if you have a list of cars like "Honda Civic", "Honda Accord", etc.; how can you just type in Honda and have all the Honda results show while all the Toyota, Mazdas, etc. don't show?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Searching database with partial name

    There's no way to specifically filter a ListView. To "filter" the data you basically have to remove the items you don't want to display. Not ideal.
    vb.net Code:
    1. Dim item As ListViewItem
    2.  
    3. For index As Integer = myListView.Items.Count -1 To 0 Step -1
    4.     If myListView.Items(index).Text.Contains("Honda") Then
    5.         myListView.Items.RemoveAt(index)
    6.     End If
    7. Next
    A better option would be to bind data to a DataGridView via a BindingSource. Then you can genuinely filter the data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    13

    Re: Searching database with partial name

    your code worked perfectly ... and if I knew how to do the other thing you suggested I would (luckily this is just for a demo to get tester feedback) ... thank you again

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