Combobox.Text unexpected behavior (C#)  
Author Message
ThePatrickP





PostPosted: Windows Forms General, Combobox.Text unexpected behavior (C#) Top

(C#, VS 2005) I have a Combobox (free typing + preset options) that is used to enter a name. On it's Validated Event I want to check if the name already exists in the (Array)List. If it does, I want to change the text of the combobox back to the old value. The code is something like this:

string oldName = ListOfNames[0];
string newName = myCombobox.Text;
if(ListOfNames.Contains(newName) {
    MessageBox.Show("Name already exists in the list.");
    myCombobox.Text = oldName;
}
else {
    ListOfNames[0] = newName;
}</code>

It doesn't work the way I want it to. When It validates and the name already exists, the messagebox pops up, the name is changed back, but quickly changed back again (newName &amp;gt; oldName &amp;gt; newName). The oldName is not visible to the eye because it is immideatly changed again. Then, when you validate again (right after the first try) it works fine. Any help is appreciated.


Windows Forms12