Results 1 to 2 of 2

Thread: vb.net go through all items in listbox and select closest matches

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2011
    Posts
    137

    Smile vb.net go through all items in listbox and select closest matches

    I have one button find,2 textboxes and one listbox.
    I need code which would go through all items in listbox and select only closest matches and add them to another multiple textbox2 as you type in textbox1.

    It find text as you type in textbox1 correctly but then i click the button find it can't find all sentence only one word like "live" not like "i live ok".

    i have only this code for so far.

    Code:
     Dim s As String = Me.TextBox1.Text
            Dim lb As ListBox = Me.ListBox1
            lb.SelectedIndex = -1
            If s.Length > 0 Then
                For i As Integer = 0 To lb.Items.Count - 1
                    If lb.Items(i).ToString.Contains(s) Then
                        lb.SelectedIndices.Add(i)
                    End If
                Next
            End If
    what a code is doing so it's trying to find exact words/strings in listbox using textbox and highlight them if they found in listbox.
    But there is the problem with this code is that one can't search and find all words like these "i live ok" without the quotes.

    It can find only entered text in textbox like this "live"
    It can't find them i live ok it finds only one word not all sentence.

    I need code that which can search through all items in listbox and select all words like "i live ok" not like so "live".
    to understand it better how is working i have some examples.

    Name:  1.png
Views: 1503
Size:  27.3 KB

    Name:  2.png
Views: 1387
Size:  37.0 KB
    Last edited by polas; May 11th, 2013 at 04:03 AM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: vb.net go through all items in listbox and select closest matches

    its not finding anything because there is no "i live ok" string contained in the data your showing

    if you want to find any of the words contained in "i live ok" you will need to separate them and do separate searches for each one and combine the results

    just break down the 'find' text into words, be sure to use a delimiter, semi-colon maybe (dont use spaces because then you cant search for 2 word strings or more)

    put it in a list and perform the search.

    hope this helps
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


Tags for this Thread

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