When the value of the Text property of a ComboBox control, (DropDown style),
EXACTLY matches an entry in the Items property then the SelectedIndex
property reflects the ordinal position of that entry in the Items property
and the SelectedItem reflects that entry.
When the value of the Text property of a ComboBox control, (DropDown style),
boes NOT EXACTLY match any entries in the Items property then the
SelectedIndex property is -1 and the SelectedItem property is Nothing.
You will be aware, (or you should be), that when you change selections, the
SelectedIndexChanged event is raised twice. The first time is when the
current item becomes unselected (SelectedIndex = -1 and SelectedItem Is
Nothing). The second time is when the new item becomes selected
(SelectedIndex = <ordinal position> and SelectedItem Is <item>.
When you attempt to use the Text property in the manner you appear to be
describing you must forget about using the KeyDown and KeyUp events and
instead react to a signal that the user has finished typing what he wants to
type.
This is easily down by using the Enter (Return) key and trapping it in the
KeyPress event.
In that event handler you need to locate the value of the Text property in
the Items property and set the SelectedIndex or SelectedItem accordingly.
You will, of course need to add any necessary code to take care of any case
sensitivity/insensitivity issues introduced by your business rules.
This, of course, is all very well for selecting items, but what about
renaming an existing selection.
This can get complicated because you have to know whetehr your user is
typing to locate an item or typing to rename an item. The Text property of
the ComboBox is not well suited for this purpose.
In my opinion, it would be better to have a seperate TextBox control for
this purpose.