Results 1 to 3 of 3

Thread: [RESOLVED] Listbox or checkedlistview search

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Posts
    92

    Resolved [RESOLVED] Listbox or checkedlistview search

    Greetings

    i got a listbox and a textbox, i been trying to get this to search for a word and when it finds the word it returns the whole line. For example if iam searching for "dog" it returns all with "dog" its only returning the exact word. it will not return both with upper and lower case. i been useing this code.
    it loads a text file in a listbox first
    or how to loop thru a checked listview

    Thank you

    Dem


    Code:
    For i As Integer = 0 To (Me.Special_Search_Histroy_CheckedListview.CheckedItems.Count - 1)
    
    
                Dim path As String = (Me.Special_Search_Histroy_CheckedListview.CheckedItems(i).SubItems(0).Text)
    
              
    
    
                Dim strr As String = (Me.Special_Search_TextBox.Text)
                'Dim path As String = (Me.load_special_search_listbox.Items.ToString)
    
                Dim readText() As String = File.ReadAllLines(path)
    
                For Each s As String In readText
    
                    If s.Contains(strr ) Then
                        MsgBox(s)
    
    
                    End If
    
    
                    'End If
                Next

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Listbox or checkedlistview search

    I think Contains is always case sensitive, however you can use IndexOf instead and specify case-insensitivity :

    Code:
            If s.IndexOf(strr, StringComparison.OrdinalIgnoreCase) <> -1 Then
                MessageBox.Show(s)
            End If
    Or alternatively you can just convert both string to lower or uppercase before comparing (ie use s.ToLower and strr.ToLower)
    Last edited by keystone_paul; Jul 19th, 2009 at 03:39 AM. Reason: Amended return check!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2008
    Posts
    92

    Re: Listbox or checkedlistview search

    Thank you

    i was trying the StringComparison.OrdinalIgnoreCase but using it wrong Totaly wrong, Thank you it works perfic :-)

    Best regards

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