1
votes

We have a ComboBox (Dropdown style) with AutoCompleteMode = SuggestAppend and AutoCompleteSource = ListItems.

Whenever we open the dropdown list and then start writing in the text field part of the combobox, the sugest box covers the list of all dropdown values but the dropdown value list still remains with focus and we can't select any items in the sugest box.

This is a very annoying behavior, and i hope it's not its default behavior. Someone else have had the same problem and found out how to prevent it?

1
I'm using AutoCompleteMode = Append in that kind of situations and it works great. Did you try to change you AutoCompleteMode into Append? try itSylca

1 Answers

1
votes

You are you using AutoCompleteMode property. Your problem is that the suggest box covers the list dropdown list. Here is an alternative way of autocomplete.

//ComboBox TextChanged Event
    private void txtName1_TextChanged(object sender, EventArgs e)
    {
        SqlDataAdapter daTemp = new SqlDataAdapter("select Name from Names where Name like '" + txtName1.Text + "%'", strConnection);
        DataTable dtTemp = new DataTable();
        daTemp.Fill(dtTemp);
        MessageBox.Show(dtTemp.Rows.Count.ToString());
        String[] Names = new String[dtTemp.Rows.Count + 1];
        if (dtTemp.Rows.Count > 0)
        {
            for (int x = 0; x <= dtTemp.Rows.Count - 1; x++)
            {
                Names[x] = dtTemp.Rows[x][0].ToString();
            }
        }
        else
        {
            MessageBox.Show("Data not found");
        }
        contextMenuStrip1.Items.Clear();
        for (int y = 0; y <= dtTemp.Rows.Count - 1; y++)
        {
            //Set The Desired Location (e.g. Besides of ComboBox) Of ContextMenuStrip
            contextMenuStrip1.Left = 80;
            contextMenuStrip1.Top = 90;
            contextMenuStrip1.Items.Add(Names[y].ToString());
            contextMenuStrip1.Visible = true;
        }
    }

The same thing can be applied to DropDownLost. Now you select the appropriate value from the ContextMenuStrip and give it to Your ComboBox (or DropDownList). To do that add the following code to ItemClicked event of the ContextMenuStrip.

private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {
        txtName1.Text = e.ClickedItem.ToString();
    }