|
-
Jun 18th, 2003, 02:51 PM
#1
Thread Starter
Lively Member
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???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|