Results 1 to 4 of 4

Thread: [RESOLVED] Search combobox using instr

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    115

    Resolved [RESOLVED] Search combobox using instr

    Hi all

    I am creating a movie player which lists movie files from various folders/subfolders in a combobox (tsFileList). I'd like to be able to enter the movie name into a textbox (txtSearch), find that text in the combobox (using instr), then automatically select the found item.

    I'd like to use instr as some of the items in the combobox contains full file paths.

    Any help would be greatly appreciated as I can't seem to find an answer for this in a web search.

    Regards
    Colin

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Search combobox using instr

    Have you looked at AutoComplete?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Search combobox using instr

    Code:
            Dim found As Boolean = False
            If TextBox1.Text = "" Then Exit Sub
            For x As Integer = 0 To ComboBox1.Items.Count - 1
                If ComboBox1.Items(x).ToString.Contains(TextBox1.Text) Then
                    ComboBox1.SelectedIndex = x
                    found = True
                    Exit For
                End If
            Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    115

    Re: Search combobox using instr

    Thanks dbasnett

    Code worked great. Modified it as shown below to enable search to resume from last found item.
    Code:
    1:
            For x As Integer = n To tsFileList.Items.Count - 1
                If tsFileList.Items(x).ToString.Contains(txtSearch.Text) Then
                    tsFileList.SelectedIndex = x
                    found = True
                    prompt = MsgBox("Search again?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "")
                    If prompt = vbNo Then
                        Exit Sub
                    ElseIf prompt = vbYes Then
                        n = x + 1
                        GoTo 1
                    End If
                    Exit For
                End If
            Next
    That really helped me out.

    kindest regards
    Colin

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