WinForms ComboBox DropDown and Autocomplete window both appear

后端 未结 10 1262
礼貌的吻别
礼貌的吻别 2020-12-05 17:41

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

comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource         


        
相关标签:
10条回答
  • 2020-12-05 17:55

    I'm a Brasilian student of encoding and I lose many hours seeking to fix it im my project. And here, I saw it in a few seconds!!!

    My code seems like this:

    private void populateCombos()
        {
            persist.ShowLst(dspMember, vlMember,varTable,lstBox,varWhere);
            persist.ShowLst(dspMember, vlMember,varTable,ddlist1,varWhere);
            persist.ShowLst(dspMember, vlMember,varTable, ddlist2,varWhere);
    
            ddList1.Text = null;
            ddList2.Text = null;
    
            lstBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            lstBox.AutoCompleteSource = AutoCompleteSource.ListItems;
            lstBox.Text = null;
        }
    
    0 讨论(0)
  • 2020-12-05 17:55

    Select the ComboBox from the design view and set "Append" to the AutoCompleteMode property, this will suggest the item without apearing a window.

    0 讨论(0)
  • 2020-12-05 17:58

    You simply add item in collection.

    Now go properties option of combo box choose AutoCompleteSource=ListItems AutocompleteMode=suggest

    note: autocomplete source have many option as per your requirement :)

    0 讨论(0)
  • 2020-12-05 18:01

    Select the ComboBox from the design view and set "None" to the AutoCompleteMode property.

    0 讨论(0)
  • 2020-12-05 18:15

    Add to the/a keypress event.

        Dim box As ComboBox = sender
        box.DroppedDown = False
    
    0 讨论(0)
  • 2020-12-05 18:15

    WinForms ComboBox DropDown...the answer is this...
    write below code in comboBox1 Enter event..

    private void comboBox1_Enter(object sender, EventArgs e)
    {
        comboBox1.DroppedDown = true;
    }
    

    Now for comboBox1 AutoComplete...
    write this AutoComplete() in page load event..so it work...

    public void AutoComplete()
    {
        try
        {
            MySqlConnection conn = new 
            MySqlConnection("server=localhost;database=databasename;user
                id=root;password=;charset=utf8;");
            MySqlCommand cmd = new MySqlCommand("select distinct
                (columnName) from tablename", conn);
            DataSet ds = new DataSet();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            da.Fill(ds, "tablename");
            AutoCompleteStringCollection col = new
            AutoCompleteStringCollection();
    
            int i = 0;
            for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
            {
                col.Add(ds.Tables[0].Rows[i]["columnName"].ToString());
            }
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            comboBox1.AutoCompleteCustomSource = col;
            comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
        MessageBoxIcon.Error);
        }
    }
    
    0 讨论(0)
提交回复
热议问题