Thanks for the complete answer.
I didn't know there was such a connection between the textbox and the items.
"Stephany Young" <noone@localhost> wrote in message
news:e0dbHu1GIHA.3600@TK2MSFTNGP06.phx.gbl...
> 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.
>
>
> "Academia" <academiaNOSPAM@a-znet.com> wrote in message
> news:u0ZThf0GIHA.3548@TK2MSFTNGP06.phx.gbl...
>>I fill the itemcollection with strings. Then the user can select an item
>>which puts it into the textbox so the user can modify it. As he changes
>>the text in the textbox KeyUp changes the SelectedItem's text. But if he
>>clears the textbox while changing it, the selectedindex no longer points
>>to the item being worked on.
>>
>> Briefly, I want the user to be able to update any item in the conbobox's
>> itemcollection.
>>
>> thanks
>>
>> "Patrice" <
http://www.chez.com/scribe/> wrote in message
>> news:OJiY31vGIHA.4712@TK2MSFTNGP04.phx.gbl...
>>> AFAIK the dropdowncontrol works this way (with the DropDown style) :
>>> - either the user selects an entry in the list and the selectedindex is
>>> then the index of the selected item
>>> - if the user enters some text, then by definition he didn't select an
>>> item so selectedindex is -1
>>>
>>> If you want the dropdown style use the Text property to know the value
>>> of the selected entry or the text entered by the user (that match or not
>>> a possible entry).
>>>
>>> If you want to constraint the user to one of those entries, use the
>>> DropDownList style.
>>>
>>> You could check yourself to which entry the text entered by the user
>>> match and reselect the corresponding item but it wuld defeat the purpose
>>> of the dropdown style and of course it could match or not depending on
>>> what the user entered.
>>>
>>> For now I'm not sure to understand. You may want to explain what you
>>> want to do (that is to let the user select between several items or only
>>> those or to let the user select between items OR enter some text freely
>>> that could match or not one of these items).
>>>
>>> --
>>> Patrice
>>>
>>> "Academia" <academiaNOSPAM@a-znet.com> a écrit dans le message de news:
>>> eQveIbvGIHA.3768@TK2MSFTNGP06.phx.gbl...
>>>>
>>>> "Patrice" <
http://www.chez.com/scribe/> wrote in message
>>>> news:OvpWHouGIHA.2540@TK2MSFTNGP05.phx.gbl...
>>>>> It looks like expected to me as SelectedIndex indicates which entry in
>>>>> the list is selected (-1 if none). You could set the index to the
>>>>> empty string item (if you have one ?) if you really need to have
>>>>> something selected.
>>>>
>>>> DropDownStyle is DropDown
>>>> AutoCompleteMode is None
>>>>
>>>> I need to know which item is selected when the user changes the text
>>>> box so that I can then replaced the selected entry's text with the user
>>>> input. But if while he is typing he clears the box the selectedIndex
>>>> changes to -1. I can't figure why they change the SelectedIndex because
>>>> the text box has changed. Can you?
>>>>
>>>> Does the textbox drive the selection in some way? I know selecting can
>>>> fill the textbox but can changing text box change the SelectionIndex?
>>>>
>>>> I tried saving SelectedIndex and resetting it but I think that may
>>>> cause side effects such as raised events.
>>>>
>>>> Thanks
>>>>
>>>>>
>>>>> Note also that depending on what you are trying to do, you could
>>>>> perhaps also use a texbox with AutoCompletion capabilities (new in
>>>>> 2.0)...
>>>>>
>>>>> --
>>>>> Patrice
>>>>>
>>>>> "Academia" <academiaNOSPAM@a-znet.com> a écrit dans le message de
>>>>> news: efWcb2mGIHA.4196@TK2MSFTNGP04.phx.gbl...
>>>>>>I let the use modify the text of a combobox and then I replace the
>>>>>>selected item with the new text (in Keyup event).
>>>>>>
>>>>>> But if he sets the Text property to an empty string ("") that sets
>>>>>> the SelectedIndex to -1.
>>>>>>
>>>>>> Do you have any suggestion for getting around this problem?
>>>>>>
>>>>>>
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>