Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Best Matched ListView

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    35

    Resolved [RESOLVED] [2005] Best Matched ListView

    I am trying to figure out how to select the best matched item. this is what i got so fare, but it only find the exect one:

    vb Code:
    1. Dim Itms As ListViewItem = ListView1.FindItemWithText(TextBox1.Text, True, 0, False)        
    2.     If Not (Itm Is Nothing) Then  
    3.         ListView1.Items(Itms.Index).Selected = True    
    4.         ListView1.EnsureVisible(Itms.Index)      
    5.         ListView1.Focus()    
    6.     Else      
    7.         MessageBox.Show("No Items Where Found In The List")  
    8.     End If

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

    Re: [2005] Best Matched ListView

    Have you read the documentation for the ListView.FindItemWithText method? It only finds an exact match because you are SPECIFICALLY telling to only find an exact match:
    The text parameter can specify a substring of the desired matching text. This method will return the first item that starts with the specified text, unless false is passed in for isPrefixSearch. For example, if a ListView contains two list items—the first item's text set to "angle bracket" and the second item's text set to "bracket"—a call to FindItemWithText passing "brack" as the search text will return the item whose text is "bracket". If isPrefixSearch is set to false, this call will return a null reference (Nothing in Visual Basic).
    You should be specifying True for the last parameter or, given that that's the default behaviour, just don't specify a fourth parameter at all. Please read the documentation first in future.
    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
    Member
    Join Date
    Jul 2005
    Posts
    35

    Re: [2005] Best Matched ListView

    but when i get rid of it my loop continues for ever

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    35

    Re: [2005] Best Matched ListView

    o i found my problem. its the code following it , thanks

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

    Re: [RESOLVED] [2005] Best Matched ListView

    Well, if that was the problem then that should have been the problem you posted. You can't just change parameter values arbitrarily when they are intended for a specific purpose.

    Are you saying that FindItemWithText doesn't return if you specify True as the fourth parameter? I'll wager not, because I just tested it and it worked as expected for me. My guess is that you have some sort of loop that is never exiting as a result of the way you've structured your code.
    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

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