Results 1 to 6 of 6

Thread: Incremental Search in ComboBox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    71

    Incremental Search in ComboBox

    I am trying to do an incremental search in a combobox when it is dropped down and something is typed. For example, if the items collection includes "AABBCC", "ABBCC", "ABCCCC", when I type an A, the first item is highlighted (Selected), when I add a B the highlight moves to the second item (searching for AB), and if I then press a C, highlight thr thrid(searching for ABC)

    I started with

    private void IDcomboBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (IDcomboBox.DroppedDown & e.KeyChar != (char) 8 )
    {
    int index = IDcomboBox.FindString(IDcomboBox.Text);
    IDcomboBox.SelectedIndex = index;
    IDcomboBox.SelectionStart = IDcomboBox.Text.Length;
    IDcomboBox.SelectionLength = 0;
    }
    }

    But when you press the first character, it finds the first match and then fills the textbox portion of the combobox with the entire field of data (AABBCC). If I press an A I want to highlight AABBCC in the list, but keep just A in the text box portion of the control so that I can type more and search further if I want to.

    I know this is pretty basic, but for the moment I'm stumped.

    BTW, (char) 8 is a backspace and I'm sure that can be done better to. When I tried Keys.Back I got a type mismatch between the Keys enumeration and e.KeyChar which returns a char???

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    If you want it in .NET way , then you need more code , otherwise , I prefer this way . It's working exactly the way you need (using API).
    Attached Files Attached Files

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    Thanks. I'm getting an error message though, "Invalid Solution File" - was it done in 2003? I'm using 2002. I tried to just paste the code into a new project, but it couldn't find System.Drawing and said I was missing an assembly. Being new to VS, I didn't go any further.

    G

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Yes , it's VS.NET 2003 ! You can try the converter under my sig . If not working , then let me know .

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    That did it - thanks.

    It does exactly what I want. Looks like a direct call to Windows. How does it work?

    G

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Simply , it uses SendMessage API to send custom message from the textbox (chr by chr) to the listbox that matches it's message. That's all .

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