views:

62

answers:

2

I've got a combobox on a winforms app with this code:

        comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;

        DataTable t = new DataTable();
        t.Columns.Add("ID", typeof(int));
        t.Columns.Add("Display", typeof(string));

        for (int i = 1; i < 2000; i++)
        {
            t.Rows.Add(i, i.ToString("N0"));
        }

        comboBox1.DataSource = t;
        comboBox1.ValueMember = "ID";
        comboBox1.DisplayMember = "Display";

I then follow these steps when the window opens:

  1. Click the combobox drop down button -- this displays the list of items and selects the text in the combobox
  2. Type '5', '1' ... i.e. I'm looking to use autocomplete to search for 515, 516, etc.
  3. You'll see that the autocomplete window now appears ON TOP of the drop down list. However if I mouse over, it's the obscured drop down window behind the autocomplete window that's receiving the mouse events, including the click. So I think I'm clicking on an autocomplete item but actually clicking on something totally random that I can't see.

Is this a bug in the ComboBox? I'm using Windows 7 if that matters. Am I configuring the ComboBox wrong somehow?

Note also that using the KEYBOARD uses the autocomplete drop down. So up/down arrow keys are using the front window, but the mouse is using the back window.

alt text

A: 

That's weired. Your code looks fine to me and I used this the AutoComplete feature a several times and it didn't show both the DropDown and the AutoComplete list.

My suggestion would be

  • Set the DataSource after the Display/Value Members. I can't remember why but the other caused some problems.

    comboBox1.ValueMember = "ID";
    comboBox1.DisplayMember = "Display";
    comboBox1.DataSource = t;
    
  • Set the AutoCompleteSource at the end of your code (after adding the DataSouce)

Maybe that helps.

SchlaWiener
Those changes didn't make a difference. Were you able to duplicate the problem? If not, what OS are you using? Thanks!
Clyde
+1  A: 

No problem getting a repro for this simply by setting the properties from the PropertyGrid. Behaves this way both in Win7 and Windows XP.

This is broken behavior documented in this feedback article. As indicated, Microsoft is not considering a fix. One possible workaround is to disable autocomplete in a DropDown event handler and re-enable it in a DropDownClosed event handler.

Hans Passant
ok, thanks.....that's depressing... :-)
Clyde