Note that there are some explanatory texts on larger screens.

plurals
  1. POComboBox.SelectedValue does not match displayed text when DropDownStyle = DropDownList in Windows 7
    primarykey
    data
    text
    <p>Let's say we have the following code in a Windows application:</p> <pre><code>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); </code></pre> <p>No magic here, just a <code>ComboBox</code> bound to a list of strings. The <code>TextBox</code> displays the <code>SelectedValue</code> of the <code>ComboBox</code>.</p> <p>I'm getting unexpected behavior when I type "Bucket" into the <code>ComboBox</code> and tab away. For some reason the <code>ComboBox</code> displays "Boat" but the <code>TextBox</code> displays "Bucket". I would expect them both to display "Bucket".</p> <p>It behaves as expected if I change the <code>DropDownStyle</code> to <code>DropDown</code>, 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.</p> <p>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 <code>ComboBox</code> and "Bucket" for the `TextBox'. So it seems like it's cycling through all the B's.</p> <p>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.</p> <p>If this behavior is correct, can anyone tell me what I should be doing to achieve my expected behavior?</p> <p><strong>UPDATE</strong> It would seem this <em>is</em> 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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload