Let's say we have the following code in a Windows application:
ComboBox comboBox = new ComboBox()
{
AutoCompleteMode = AutoCompleteMode.SuggestAppend,
AutoCompleteSource = AutoCompleteSource.ListItems,
DataSource = new string[] { "", "Ark", "Boat", "Bucket" },
DropDownStyle = ComboBoxStyle.DropDownList
};
this.Controls.Add(comboBox);
TextBox textBox = new TextBox()
{
Left = comboBox.Right,
Top = comboBox.Top,
ReadOnly = true
};
textBox.DataBindings.Add("Text", comboBox, "SelectedValue");
this.Controls.Add(textBox);
No magic here, just a ComboBox
bound to a list of strings. The TextBox
displays the SelectedValue
of the ComboBox
.
I'm getting unexpected behavior when I type "Bucket" into the ComboBox
and tab away. For some reason the ComboBox
displays "Boat" but the TextBox
displays "Bucket". I would expect them both to display "Bucket".
It behaves as expected if I change the DropDownStyle
to DropDown
, but I don't want users to be able to type anything they want. They should only be able to type items that are in the list.
Even more interesting is that, after typing "Bucket" and tabbing away, if I type "Bucket" again it will display "Bucket" in both. If I make a third attempt, it goes back to "Boat" for the ComboBox
and "Bucket" for the `TextBox'. So it seems like it's cycling through all the B's.
I didn't notice this until I upgraded from XP to Windows 7 recently. I don't see how that could have anything to do with this, but I'm throwing it out anyway.
If this behavior is correct, can anyone tell me what I should be doing to achieve my expected behavior?
UPDATE It would seem this is related to Windows 7. Everything behaves as expected in Windows XP Mode. Can anyone else running Windows 7 try my code and verify that I'm not crazy?